-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[clang][bytecode] Fix redeclaring global externs without initializer #164409
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
Conversation
Return the same value, whether we've already allocated the variable or not.
|
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesReturn the same value, whether we've already allocated the variable or not. Full diff: https://github.com/llvm/llvm-project/pull/164409.diff 2 Files Affected:
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 74cae030bb9bb..cc2c092e9a8bf 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4872,7 +4872,7 @@ Compiler<Emitter>::visitVarDecl(const VarDecl *VD, const Expr *Init,
// The previous attempt at initialization might've been unsuccessful,
// so let's try this one.
- return Init && checkDecl() && initGlobal(*GlobalIndex);
+ return !Init || (checkDecl() && initGlobal(*GlobalIndex));
}
UnsignedOrNone GlobalIndex = P.createGlobal(VD, Init);
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp
index f47bc49d9a1a8..0b7d51be8d824 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -63,6 +63,19 @@ constexpr int test_address_of_incomplete_array_type() { // both-error {{never pr
static_assert(test_address_of_incomplete_array_type() == 1234, ""); // both-error {{constant}} \
// both-note {{in call}}
+namespace LocalExternRedecl {
+ constexpr int externRedecl1() {
+ extern int arr[];
+ return 0;
+ }
+ constexpr int externRedecl2() { // both-error {{never produces a constant expression}}
+ extern int arr[];
+ __builtin_memmove(&arr, &arr, 4 * sizeof(arr[0])); // both-note 2{{incomplete type}}
+ return 1234;
+ }
+ static_assert(externRedecl2() == 1234); // both-error {{not an integral constant expression}} \
+ // both-note {{in call to}}
+}
struct NonTrivial {
constexpr NonTrivial() : n(0) {}
|
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/88/builds/17365 Here is the relevant piece of the build log for the reference |
…lvm#164409) Return the same value, whether we've already allocated the variable or not.
…lvm#164409) Return the same value, whether we've already allocated the variable or not.
Return the same value, whether we've already allocated the variable or not.