================
@@ -14918,52 +14918,57 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl 
*var) {
   }
 
   // Apply section attributes and pragmas to global variables.
-  if (GlobalStorage && var->isThisDeclarationADefinition() &&
-      !inTemplateInstantiation()) {
-    PragmaStack<StringLiteral *> *Stack = nullptr;
-    int SectionFlags = ASTContext::PSF_Read;
-    bool MSVCEnv =
-        Context.getTargetInfo().getTriple().isWindowsMSVCEnvironment();
-    std::optional<QualType::NonConstantStorageReason> Reason;
-    if (HasConstInit &&
-        !(Reason = var->getType().isNonConstantStorage(Context, true, false))) 
{
-      Stack = &ConstSegStack;
-    } else {
-      SectionFlags |= ASTContext::PSF_Write;
-      Stack = var->hasInit() && HasConstInit ? &DataSegStack : &BSSSegStack;
-    }
-    if (const SectionAttr *SA = var->getAttr<SectionAttr>()) {
-      if (SA->getSyntax() == AttributeCommonInfo::AS_Declspec)
+  [&]() {
+    if (GlobalStorage && var->isThisDeclarationADefinition() &&
+        !inTemplateInstantiation()) {
+      PragmaStack<StringLiteral *> *Stack = nullptr;
+      int SectionFlags = ASTContext::PSF_Read;
+      bool MSVCEnv =
+          Context.getTargetInfo().getTriple().isWindowsMSVCEnvironment();
+      std::optional<QualType::NonConstantStorageReason> Reason;
+      if (HasConstInit && var->getType()->isIncompleteType())
+        return;
----------------
ahatanak wrote:

If we stop computing the section for definitions inside templated 
classes/functions altogether, clang will stop emitting error `'m' causes a 
section type conflict with 'v1'` when the following code is compiled. Is that 
okay?

```
template <class T>
struct C {
  __attribute__((section("non_trivial_ctor")))
  static constexpr int m{123};
};
```

https://github.com/llvm/llvm-project/pull/161590
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to