aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clang/lib/AST/Decl.cpp14
-rw-r--r--clang/test/CodeGen/attr-tentative-definition.c7
2 files changed, 16 insertions, 5 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index aa9fba51..835e28c 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -2216,14 +2216,18 @@ VarDecl *VarDecl::getActingDefinition() {
return nullptr;
VarDecl *LastTentative = nullptr;
- VarDecl *First = getFirstDecl();
- for (auto I : First->redecls()) {
- Kind = I->isThisDeclarationADefinition();
+
+ // Loop through the declaration chain, starting with the most recent.
+ for (VarDecl *Decl = getMostRecentDecl(); Decl;
+ Decl = Decl->getPreviousDecl()) {
+ Kind = Decl->isThisDeclarationADefinition();
if (Kind == Definition)
return nullptr;
- if (Kind == TentativeDefinition)
- LastTentative = I;
+ // Record the first (most recent) TentativeDefinition that is encountered.
+ if (Kind == TentativeDefinition && !LastTentative)
+ LastTentative = Decl;
}
+
return LastTentative;
}
diff --git a/clang/test/CodeGen/attr-tentative-definition.c b/clang/test/CodeGen/attr-tentative-definition.c
new file mode 100644
index 0000000..0c49894e
--- /dev/null
+++ b/clang/test/CodeGen/attr-tentative-definition.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-unknown < %s | FileCheck %s
+
+char arr[10];
+char arr[10] __attribute__((section("datadata")));
+char arr[10] __attribute__((aligned(16)));
+
+// CHECK: @arr ={{.*}}section "datadata", align 16