[PATCH] D138247: PR58819: Correct linkage and mangling of lambdas in inline static member initializers

2023-04-03 Thread David Blaikie via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe9c9db34a9b0: PR58819: Correct linkage and mangling of 
lambdas in inline static member… (authored by dblaikie).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138247/new/

https://reviews.llvm.org/D138247

Files:
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CodeGenCXX/mangle-lambdas.cpp

Index: clang/test/CodeGenCXX/mangle-lambdas.cpp
===
--- clang/test/CodeGenCXX/mangle-lambdas.cpp
+++ clang/test/CodeGenCXX/mangle-lambdas.cpp
@@ -290,6 +290,17 @@
 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZZ3ft4IiEvvEN2lc2mfEiEd_NKUlvE_clEv
 
 
+extern int ExternalVariable;
+struct StaticInlineMember {
+  static constexpr auto x = [] { return ExternalVariable; };
+};
+
+// CHECK-LABEL: define void @_Z23test_StaticInlineMemberv
+// CHECK: call {{.*}} @_ZNK18StaticInlineMember1xMUlvE_clEv
+void test_StaticInlineMember() {
+  StaticInlineMember::x();
+}
+
 // Check linkage of the various lambdas.
 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ11inline_funciENKUlvE_clEv
 // CHECK: ret i32 1
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -283,12 +283,14 @@
 Normal,
 DefaultArgument,
 DataMember,
-StaticDataMember,
 InlineVariable,
-VariableTemplate,
+TemplatedVariable,
 Concept
   } Kind = Normal;
 
+  bool IsInNonspecializedTemplate =
+  inTemplateInstantiation() || CurContext->isDependentContext();
+
   // Default arguments of member function parameters that appear in a class
   // definition, as well as the initializers of data members, receive special
   // treatment. Identify them.
@@ -299,15 +301,15 @@
 if (LexicalDC->isRecord())
   Kind = DefaultArgument;
 } else if (VarDecl *Var = dyn_cast(ManglingContextDecl)) {
-  if (Var->getDeclContext()->isRecord())
-Kind = StaticDataMember;
-  else if (Var->getMostRecentDecl()->isInline())
+  if (Var->getMostRecentDecl()->isInline())
 Kind = InlineVariable;
+  else if (Var->getDeclContext()->isRecord() && IsInNonspecializedTemplate)
+Kind = TemplatedVariable;
   else if (Var->getDescribedVarTemplate())
-Kind = VariableTemplate;
+Kind = TemplatedVariable;
   else if (auto *VTS = dyn_cast(Var)) {
 if (!VTS->isExplicitSpecialization())
-  Kind = VariableTemplate;
+  Kind = TemplatedVariable;
   }
 } else if (isa(ManglingContextDecl)) {
   Kind = DataMember;
@@ -319,12 +321,9 @@
   // Itanium ABI [5.1.7]:
   //   In the following contexts [...] the one-definition rule requires closure
   //   types in different translation units to "correspond":
-  bool IsInNonspecializedTemplate =
-  inTemplateInstantiation() || CurContext->isDependentContext();
   switch (Kind) {
   case Normal: {
-//  -- the bodies of non-exported nonspecialized template functions
-//  -- the bodies of inline functions
+//  -- the bodies of inline or templated functions
 if ((IsInNonspecializedTemplate &&
  !(ManglingContextDecl && isa(ManglingContextDecl))) ||
 isInInlineFunction(CurContext)) {
@@ -341,21 +340,13 @@
 // however the ManglingContextDecl is important for the purposes of
 // re-forming the template argument list of the lambda for constraint
 // evaluation.
-  case StaticDataMember:
-//  -- the initializers of nonspecialized static members of template classes
-if (!IsInNonspecializedTemplate)
-  return std::make_tuple(nullptr, ManglingContextDecl);
-// Fall through to get the current context.
-[[fallthrough]];
-
   case DataMember:
-//  -- the in-class initializers of class members
+//  -- default member initializers
   case DefaultArgument:
 //  -- default arguments appearing in class definitions
   case InlineVariable:
-//  -- the initializers of inline variables
-  case VariableTemplate:
-//  -- the initializers of templated variables
+  case TemplatedVariable:
+//  -- the initializers of inline or templated variables
 return std::make_tuple(
 &Context.getManglingNumberContext(ASTContext::NeedExtraManglingDecl,
   ManglingContextDecl),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138247: PR58819: Correct linkage and mangling of lambdas in inline static member initializers

2023-03-30 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision as: efriedma.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138247/new/

https://reviews.llvm.org/D138247

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138247: PR58819: Correct linkage and mangling of lambdas in inline static member initializers

2023-03-27 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D138247#4217189 , @efriedma wrote:

> The relevant text of the current Itanium ABI (which was updated in 
> https://github.com/itanium-cxx-abi/cxx-abi/commit/d8e9d102c83f177970f0db6cc8bee170f2779bc1)
>
>> In the following contexts, however, the one-definition rule requires closure 
>> types in different translation units to "correspond":
>>
>> - default arguments appearing in class definitions
>> - default member initializers
>> - the bodies of inline or templated functions
>> - the initializers of inline or templated variables
>
> Could you update the references to the ABI document to use the new text?

Oh, yeah - good call. Done.

> Given the new rules, I think ContextKind::StaticDataMember shouldn't exist?  
> It's not one of the given categories; should be subsumed by the existing 
> categories.

Fair - I assume the "initializers of inline or templated variables" is intended 
to cover the case of static member variables of class templates, though they 
aren't technically variable templates presumably they are "templated variables".

So I renamed the `VariableTemplate` kind to `TemplatedVariable` to match the 
ABI wording/semantics a bit better.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138247/new/

https://reviews.llvm.org/D138247

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138247: PR58819: Correct linkage and mangling of lambdas in inline static member initializers

2023-03-27 Thread David Blaikie via Phabricator via cfe-commits
dblaikie updated this revision to Diff 508847.
dblaikie added a comment.

Rename VariableTemplate classification to TemplatedVariable to match ABI wording


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138247/new/

https://reviews.llvm.org/D138247

Files:
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CodeGenCXX/mangle-lambdas.cpp

Index: clang/test/CodeGenCXX/mangle-lambdas.cpp
===
--- clang/test/CodeGenCXX/mangle-lambdas.cpp
+++ clang/test/CodeGenCXX/mangle-lambdas.cpp
@@ -290,6 +290,17 @@
 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZZ3ft4IiEvvEN2lc2mfEiEd_NKUlvE_clEv
 
 
+extern int ExternalVariable;
+struct StaticInlineMember {
+  static constexpr auto x = [] { return ExternalVariable; };
+};
+
+// CHECK-LABEL: define void @_Z23test_StaticInlineMemberv
+// CHECK: call {{.*}} @_ZNK18StaticInlineMember1xMUlvE_clEv
+void test_StaticInlineMember() {
+  StaticInlineMember::x();
+}
+
 // Check linkage of the various lambdas.
 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ11inline_funciENKUlvE_clEv
 // CHECK: ret i32 1
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -283,12 +283,14 @@
 Normal,
 DefaultArgument,
 DataMember,
-StaticDataMember,
 InlineVariable,
-VariableTemplate,
+TemplatedVariable,
 Concept
   } Kind = Normal;
 
+  bool IsInNonspecializedTemplate =
+  inTemplateInstantiation() || CurContext->isDependentContext();
+
   // Default arguments of member function parameters that appear in a class
   // definition, as well as the initializers of data members, receive special
   // treatment. Identify them.
@@ -299,15 +301,15 @@
 if (LexicalDC->isRecord())
   Kind = DefaultArgument;
 } else if (VarDecl *Var = dyn_cast(ManglingContextDecl)) {
-  if (Var->getDeclContext()->isRecord())
-Kind = StaticDataMember;
-  else if (Var->getMostRecentDecl()->isInline())
+  if (Var->getMostRecentDecl()->isInline())
 Kind = InlineVariable;
+  else if (Var->getDeclContext()->isRecord() && IsInNonspecializedTemplate)
+Kind = TemplatedVariable;
   else if (Var->getDescribedVarTemplate())
-Kind = VariableTemplate;
+Kind = TemplatedVariable;
   else if (auto *VTS = dyn_cast(Var)) {
 if (!VTS->isExplicitSpecialization())
-  Kind = VariableTemplate;
+  Kind = TemplatedVariable;
   }
 } else if (isa(ManglingContextDecl)) {
   Kind = DataMember;
@@ -319,12 +321,9 @@
   // Itanium ABI [5.1.7]:
   //   In the following contexts [...] the one-definition rule requires closure
   //   types in different translation units to "correspond":
-  bool IsInNonspecializedTemplate =
-  inTemplateInstantiation() || CurContext->isDependentContext();
   switch (Kind) {
   case Normal: {
-//  -- the bodies of non-exported nonspecialized template functions
-//  -- the bodies of inline functions
+//  -- the bodies of inline or templated functions
 if ((IsInNonspecializedTemplate &&
  !(ManglingContextDecl && isa(ManglingContextDecl))) ||
 isInInlineFunction(CurContext)) {
@@ -341,21 +340,13 @@
 // however the ManglingContextDecl is important for the purposes of
 // re-forming the template argument list of the lambda for constraint
 // evaluation.
-  case StaticDataMember:
-//  -- the initializers of nonspecialized static members of template classes
-if (!IsInNonspecializedTemplate)
-  return std::make_tuple(nullptr, ManglingContextDecl);
-// Fall through to get the current context.
-[[fallthrough]];
-
   case DataMember:
-//  -- the in-class initializers of class members
+//  -- default member initializers
   case DefaultArgument:
 //  -- default arguments appearing in class definitions
   case InlineVariable:
-//  -- the initializers of inline variables
-  case VariableTemplate:
-//  -- the initializers of templated variables
+  case TemplatedVariable:
+//  -- the initializers of inline or templated variables
 return std::make_tuple(
 &Context.getManglingNumberContext(ASTContext::NeedExtraManglingDecl,
   ManglingContextDecl),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138247: PR58819: Correct linkage and mangling of lambdas in inline static member initializers

2023-03-27 Thread David Blaikie via Phabricator via cfe-commits
dblaikie updated this revision to Diff 508842.
dblaikie added a comment.

Remove `StaticDataMember` and classify static member variables of templates as 
variable templates


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138247/new/

https://reviews.llvm.org/D138247

Files:
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CodeGenCXX/mangle-lambdas.cpp


Index: clang/test/CodeGenCXX/mangle-lambdas.cpp
===
--- clang/test/CodeGenCXX/mangle-lambdas.cpp
+++ clang/test/CodeGenCXX/mangle-lambdas.cpp
@@ -290,6 +290,17 @@
 // CHECK-LABEL: define linkonce_odr noundef i32 
@_ZZZ3ft4IiEvvEN2lc2mfEiEd_NKUlvE_clEv
 
 
+extern int ExternalVariable;
+struct StaticInlineMember {
+  static constexpr auto x = [] { return ExternalVariable; };
+};
+
+// CHECK-LABEL: define void @_Z23test_StaticInlineMemberv
+// CHECK: call {{.*}} @_ZNK18StaticInlineMember1xMUlvE_clEv
+void test_StaticInlineMember() {
+  StaticInlineMember::x();
+}
+
 // Check linkage of the various lambdas.
 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ11inline_funciENKUlvE_clEv
 // CHECK: ret i32 1
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -283,12 +283,14 @@
 Normal,
 DefaultArgument,
 DataMember,
-StaticDataMember,
 InlineVariable,
 VariableTemplate,
 Concept
   } Kind = Normal;
 
+  bool IsInNonspecializedTemplate =
+  inTemplateInstantiation() || CurContext->isDependentContext();
+
   // Default arguments of member function parameters that appear in a class
   // definition, as well as the initializers of data members, receive special
   // treatment. Identify them.
@@ -299,10 +301,10 @@
 if (LexicalDC->isRecord())
   Kind = DefaultArgument;
 } else if (VarDecl *Var = dyn_cast(ManglingContextDecl)) {
-  if (Var->getDeclContext()->isRecord())
-Kind = StaticDataMember;
-  else if (Var->getMostRecentDecl()->isInline())
+  if (Var->getMostRecentDecl()->isInline())
 Kind = InlineVariable;
+  else if (Var->getDeclContext()->isRecord() && IsInNonspecializedTemplate)
+Kind = VariableTemplate;
   else if (Var->getDescribedVarTemplate())
 Kind = VariableTemplate;
   else if (auto *VTS = dyn_cast(Var)) {
@@ -319,12 +321,9 @@
   // Itanium ABI [5.1.7]:
   //   In the following contexts [...] the one-definition rule requires closure
   //   types in different translation units to "correspond":
-  bool IsInNonspecializedTemplate =
-  inTemplateInstantiation() || CurContext->isDependentContext();
   switch (Kind) {
   case Normal: {
-//  -- the bodies of non-exported nonspecialized template functions
-//  -- the bodies of inline functions
+//  -- the bodies of inline or templated functions
 if ((IsInNonspecializedTemplate &&
  !(ManglingContextDecl && isa(ManglingContextDecl))) ||
 isInInlineFunction(CurContext)) {
@@ -341,21 +340,13 @@
 // however the ManglingContextDecl is important for the purposes of
 // re-forming the template argument list of the lambda for constraint
 // evaluation.
-  case StaticDataMember:
-//  -- the initializers of nonspecialized static members of template 
classes
-if (!IsInNonspecializedTemplate)
-  return std::make_tuple(nullptr, ManglingContextDecl);
-// Fall through to get the current context.
-[[fallthrough]];
-
   case DataMember:
-//  -- the in-class initializers of class members
+//  -- default member initializers
   case DefaultArgument:
 //  -- default arguments appearing in class definitions
   case InlineVariable:
-//  -- the initializers of inline variables
   case VariableTemplate:
-//  -- the initializers of templated variables
+//  -- the initializers of inline or templated variables
 return std::make_tuple(
 &Context.getManglingNumberContext(ASTContext::NeedExtraManglingDecl,
   ManglingContextDecl),


Index: clang/test/CodeGenCXX/mangle-lambdas.cpp
===
--- clang/test/CodeGenCXX/mangle-lambdas.cpp
+++ clang/test/CodeGenCXX/mangle-lambdas.cpp
@@ -290,6 +290,17 @@
 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZZ3ft4IiEvvEN2lc2mfEiEd_NKUlvE_clEv
 
 
+extern int ExternalVariable;
+struct StaticInlineMember {
+  static constexpr auto x = [] { return ExternalVariable; };
+};
+
+// CHECK-LABEL: define void @_Z23test_StaticInlineMemberv
+// CHECK: call {{.*}} @_ZNK18StaticInlineMember1xMUlvE_clEv
+void test_StaticInlineMember() {
+  StaticInlineMember::x();
+}
+
 // Check linkage of the various lambdas.
 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ11inline_funciENKUlvE_clEv
 // CHECK: ret i32 1
Index: clang/lib/Sema/SemaLambda.cpp

[PATCH] D138247: PR58819: Correct linkage and mangling of lambdas in inline static member initializers

2023-03-23 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

The relevant text of the current Itanium ABI (which was updated in 
https://github.com/itanium-cxx-abi/cxx-abi/commit/d8e9d102c83f177970f0db6cc8bee170f2779bc1)

> In the following contexts, however, the one-definition rule requires closure 
> types in different translation units to "correspond":
>
> - default arguments appearing in class definitions
> - default member initializers
> - the bodies of inline or templated functions
> - the initializers of inline or templated variables

Could you update the references to the ABI document to use the new text?

Given the new rules, I think ContextKind::StaticDataMember shouldn't exist?  
It's not one of the given categories; should be subsumed by the existing 
categories.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138247/new/

https://reviews.llvm.org/D138247

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138247: PR58819: Correct linkage and mangling of lambdas in inline static member initializers

2023-03-22 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138247/new/

https://reviews.llvm.org/D138247

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138247: PR58819: Correct linkage and mangling of lambdas in inline static member initializers

2023-03-06 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

GCC bug hasn't got much traction, so I pinged it.

But probably still the right thing to continue with this fix, I think.

@rjmccall Could you give a quick glance/confirm my ABI 
understanding/diagnosis/direction here?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138247/new/

https://reviews.llvm.org/D138247

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138247: PR58819: Correct linkage and mangling of lambdas in inline static member initializers

2022-11-22 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D138247#3942744 , @mgorny wrote:

> From Gentoo perspective, correct is better, correct and matching GCC is the 
> best (we support mixing compilers to some degree). I think it'd be best to 
> wait for confirmation on GCC end.

fair - if you know anyone over there who might be able to take a look/an 
interest, would be great if you could ping them/point them in that direction!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138247/new/

https://reviews.llvm.org/D138247

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138247: PR58819: Correct linkage and mangling of lambdas in inline static member initializers

2022-11-21 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

From Gentoo perspective, correct is better, correct and matching GCC is the 
best (we support mixing compilers to some degree). I think it'd be best to wait 
for confirmation on GCC end.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138247/new/

https://reviews.llvm.org/D138247

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138247: PR58819: Correct linkage and mangling of lambdas in inline static member initializers

2022-11-18 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D138247#3936928 , @probinson wrote:

> If this is specifically for C++17, I believe Sony doesn't officially support 
> that yet although I am checking.

Cool, thanks!

> It looks like this is only part of the fix for #58819? The original report 
> also had a `static int n` with an internal-linkage name.

Nah, it's the full fix - but the static member handling works correctly once 
you fix the type mangling itself, so the bug is in the type linkage/mangling, 
the static member was just the canary in the coal mine/a more visible effect of 
the bug. I could add test coverage for it, but by default I prefer to test more 
narrowly.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138247/new/

https://reviews.llvm.org/D138247

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138247: PR58819: Correct linkage and mangling of lambdas in inline static member initializers

2022-11-18 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

If this is specifically for C++17, I believe Sony doesn't officially support 
that yet although I am checking.

It looks like this is only part of the fix for #58819? The original report also 
had a `static int n` with an internal-linkage name.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138247/new/

https://reviews.llvm.org/D138247

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138247: PR58819: Correct linkage and mangling of lambdas in inline static member initializers

2022-11-17 Thread David Blaikie via Phabricator via cfe-commits
dblaikie created this revision.
dblaikie added reviewers: clang-vendors, rsmith, probinson, rjmccall.
Herald added a project: All.
dblaikie requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

https://llvm.org/pr58819 - clang is giving an externally visible lambda in a 
static data member internal linkage and the wrong linkage name.

Looks like we should be classifying this case the same as a non-static data 
member, so far as I can tell from the ABI docs and template examples (seems 
like the non-template inline-defined case should be the same).

This is a change in ABI, but not sure it qualifies as an ABI break as far as 
Apple and Sony are concerned - do you folks want this change? (it should fix 
the example in the bug where a static member in such a lambda ends up 
bifurcated, and I don't /think/ it'll break existing code since the symbol was 
previously internal anyway)

Looks like GCC has got this mangling slightly wrong (so we'd still end up with 
GCC+Clang bifurcation of the local static in the lambda, function address 
inequality, etc) in that they miss the variable name in the mangling in the 
non-template case. GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107741


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138247

Files:
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CodeGenCXX/mangle-lambdas.cpp


Index: clang/test/CodeGenCXX/mangle-lambdas.cpp
===
--- clang/test/CodeGenCXX/mangle-lambdas.cpp
+++ clang/test/CodeGenCXX/mangle-lambdas.cpp
@@ -290,6 +290,17 @@
 // CHECK-LABEL: define linkonce_odr noundef i32 
@_ZZZ3ft4IiEvvEN2lc2mfEiEd_NKUlvE_clEv
 
 
+extern int ExternalVariable;
+struct StaticInlineMember {
+  static constexpr auto x = [] { return ExternalVariable; };
+};
+
+// CHECK-LABEL: define void @_Z23test_StaticInlineMemberv
+// CHECK: call {{.*}} @_ZNK18StaticInlineMember1xMUlvE_clEv
+void test_StaticInlineMember() {
+  StaticInlineMember::x();
+}
+
 // Check linkage of the various lambdas.
 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ11inline_funciENKUlvE_clEv
 // CHECK: ret i32 1
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -296,10 +296,10 @@
 if (LexicalDC->isRecord())
   Kind = DefaultArgument;
 } else if (VarDecl *Var = dyn_cast(ManglingContextDecl)) {
-  if (Var->getDeclContext()->isRecord())
-Kind = StaticDataMember;
-  else if (Var->getMostRecentDecl()->isInline())
+  if (Var->getMostRecentDecl()->isInline())
 Kind = InlineVariable;
+  else if (Var->getDeclContext()->isRecord())
+Kind = StaticDataMember;
   else if (Var->getDescribedVarTemplate())
 Kind = VariableTemplate;
   else if (auto *VTS = dyn_cast(Var)) {


Index: clang/test/CodeGenCXX/mangle-lambdas.cpp
===
--- clang/test/CodeGenCXX/mangle-lambdas.cpp
+++ clang/test/CodeGenCXX/mangle-lambdas.cpp
@@ -290,6 +290,17 @@
 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZZ3ft4IiEvvEN2lc2mfEiEd_NKUlvE_clEv
 
 
+extern int ExternalVariable;
+struct StaticInlineMember {
+  static constexpr auto x = [] { return ExternalVariable; };
+};
+
+// CHECK-LABEL: define void @_Z23test_StaticInlineMemberv
+// CHECK: call {{.*}} @_ZNK18StaticInlineMember1xMUlvE_clEv
+void test_StaticInlineMember() {
+  StaticInlineMember::x();
+}
+
 // Check linkage of the various lambdas.
 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ11inline_funciENKUlvE_clEv
 // CHECK: ret i32 1
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -296,10 +296,10 @@
 if (LexicalDC->isRecord())
   Kind = DefaultArgument;
 } else if (VarDecl *Var = dyn_cast(ManglingContextDecl)) {
-  if (Var->getDeclContext()->isRecord())
-Kind = StaticDataMember;
-  else if (Var->getMostRecentDecl()->isInline())
+  if (Var->getMostRecentDecl()->isInline())
 Kind = InlineVariable;
+  else if (Var->getDeclContext()->isRecord())
+Kind = StaticDataMember;
   else if (Var->getDescribedVarTemplate())
 Kind = VariableTemplate;
   else if (auto *VTS = dyn_cast(Var)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits