Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NativeAOT-LLVM] Ilc assert with locals in release config #2682

Open
yowl opened this issue Sep 10, 2024 · 4 comments
Open

[NativeAOT-LLVM] Ilc assert with locals in release config #2682

yowl opened this issue Sep 10, 2024 · 4 comments

Comments

@yowl
Copy link
Contributor

yowl commented Sep 10, 2024

This IL seems to cause an assert

// [PresentationFramework]System.Windows.FrameworkTemplate.WireRootObjectToParent(object,DependencyObject,DependencyObject,FrameworkElement,INameScope)
.method class [WindowsBase]System.Windows.DependencyObject WireRootObjectToParent(object, class [WindowsBase]System.Windows.DependencyObject, class [WindowsBase]System.Windows.DependencyObject, class System.Windows.FrameworkElement, class [System.Xaml]System.Windows.Markup.INameScope) cil managed
{
  // Code size: 124
  .maxstack 5
  .locals init (class [PresentationCore]System.Windows.UIElement V_0,
      class System.Windows.FrameworkElement V_1,
      class System.Windows.FrameworkContentElement V_2)

  IL_0000:  ldarg.0
  IL_0001:  isinst      [WindowsBase]System.Windows.DependencyObject
  IL_0006:  starg.s     1
  IL_0008:  ldarg.1
  IL_0009:  brfalse.s   IL_007A
  IL_000B:  ldarg.3
  IL_000C:  brfalse.s   IL_0045
  IL_000E:  ldarg.1
  IL_000F:  isinst      [PresentationCore]System.Windows.UIElement
  IL_0014:  stloc.0
  IL_0015:  ldloc.0
  IL_0016:  brtrue.s    IL_003C
  IL_0018:  ldstr       "TemplateMustBeFE"
  IL_001D:  ldc.i4.1
  IL_001E:  newarr      object
  IL_0023:  dup
  IL_0024:  ldc.i4.0
  IL_0025:  ldarg.1
  IL_0026:  callvirt    instance class [System.Private.CoreLib]System.Type [System.Private.CoreLib]System.Object::GetType()
  IL_002B:  callvirt    instance string [System.Private.CoreLib]System.Type::get_FullName()
  IL_0030:  stelem.ref
  IL_0031:  call        string System.Windows.SR::Get(string, object[])
  IL_0036:  newobj      instance void [System.Private.CoreLib]System.InvalidOperationException::.ctor(string)
  IL_003B:  throw
  IL_003C:  ldarg.3
  IL_003D:  ldloc.0
  IL_003E:  callvirt    instance void System.Windows.FrameworkElement::set_TemplateChild(class [PresentationCore]System.Windows.UIElement)
  IL_0043:  br.s        IL_006A
  IL_0045:  ldarg.2
  IL_0046:  brfalse.s   IL_006A
  IL_0048:  ldarg.1
  IL_0049:  ldloca.s    1
  IL_004B:  ldloca.s    2
  IL_004D:  ldc.i4.1
  IL_004E:  call        void MS.Internal.Helper::DowncastToFEorFCE(class [WindowsBase]System.Windows.DependencyObject, class System.Windows.FrameworkElement&, class System.Windows.FrameworkContentElement&, bool)
  IL_0053:  ldarg.2
  IL_0054:  castclass   System.Windows.FrameworkContentElement
  IL_0059:  ldarg.1
  IL_005A:  callvirt    instance class [System.Private.CoreLib]System.Type [System.Private.CoreLib]System.Object::GetType()
  IL_005F:  ldloc.1
  IL_0060:  ldnull
  IL_0061:  cgt.un
  IL_0063:  ldloc.1
  IL_0064:  ldloc.2
  IL_0065:  call        void System.Windows.FrameworkElementFactory::AddNodeToLogicalTree(class [WindowsBase]System.Windows.DependencyObject, class [System.Private.CoreLib]System.Type, bool, class System.Windows.FrameworkElement, class System.Windows.FrameworkContentElement)
  IL_006A:  ldarg.1
  IL_006B:  call        class [System.Xaml]System.Windows.Markup.INameScope [WindowsBase]System.Windows.NameScope::GetNameScope(class [WindowsBase]System.Windows.DependencyObject)
  IL_0070:  brtrue.s    IL_007A
  IL_0072:  ldarg.1
  IL_0073:  ldarg.s     4
  IL_0075:  call        void [WindowsBase]System.Windows.NameScope::SetNameScope(class [WindowsBase]System.Windows.DependencyObject, class [System.Xaml]System.Windows.Markup.INameScope)
  IL_007A:  ldarg.1
  IL_007B:  ret
}

at

llvmRef = _localsMap[{lclNum, ssaNum}];

Haven't done any more investigation

image

@yowl
Copy link
Contributor Author

yowl commented Sep 11, 2024

@SingleAccretion
Copy link

SingleAccretion commented Sep 11, 2024

It looks like we need to add the local to the live-in set of the first block here:

GenTreeLclVar* initValue = m_compiler->gtNewLclvNode(lclNum, varDsc->TypeGet());
initValue->SetRegNum(REG_LLVM);
if (m_compiler->lvaInSsa(lclNum))
{
initValue->SetSsaNum(SsaConfig::FIRST_SSA_NUM);
}
InitializeLocalInProlog(lclNum, initValue);

@yowl
Copy link
Contributor Author

yowl commented Sep 11, 2024

VarSetOps::AddElemD(m_compiler, m_compiler->fgFirstBB->bbLiveIn, varDsc->lvVarIndex);

Sorry, not sure I've got this right, sometimes lvaTrackedCount is 0 which causes an assert?

@SingleAccretion
Copy link

Yes, that's correct. It should be guarded by varDsc->lvTracked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants