Skip to content

Commit 7b91bb2

Browse files
authored
[clang][bytecode] Fix redeclaring global externs without initializer (#164409)
Return the same value, whether we've already allocated the variable or not.
1 parent da48e41 commit 7b91bb2

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4872,7 +4872,7 @@ Compiler<Emitter>::visitVarDecl(const VarDecl *VD, const Expr *Init,
48724872

48734873
// The previous attempt at initialization might've been unsuccessful,
48744874
// so let's try this one.
4875-
return Init && checkDecl() && initGlobal(*GlobalIndex);
4875+
return !Init || (checkDecl() && initGlobal(*GlobalIndex));
48764876
}
48774877

48784878
UnsignedOrNone GlobalIndex = P.createGlobal(VD, Init);

clang/test/AST/ByteCode/builtin-functions.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ constexpr int test_address_of_incomplete_array_type() { // both-error {{never pr
6363
static_assert(test_address_of_incomplete_array_type() == 1234, ""); // both-error {{constant}} \
6464
// both-note {{in call}}
6565

66+
namespace LocalExternRedecl {
67+
constexpr int externRedecl1() {
68+
extern int arr[];
69+
return 0;
70+
}
71+
constexpr int externRedecl2() { // both-error {{never produces a constant expression}}
72+
extern int arr[];
73+
__builtin_memmove(&arr, &arr, 4 * sizeof(arr[0])); // both-note 2{{incomplete type}}
74+
return 1234;
75+
}
76+
static_assert(externRedecl2() == 1234); // both-error {{not an integral constant expression}} \
77+
// both-note {{in call to}}
78+
}
6679

6780
struct NonTrivial {
6881
constexpr NonTrivial() : n(0) {}

0 commit comments

Comments
 (0)