-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][bytecode] Create local scopes for if then/else statements #120852
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
In case those aren't compound statements.
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesIn case those aren't compound statements. Full diff: https://github.com/llvm/llvm-project/pull/120852.diff 2 Files Affected:
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 59c77f0ce78d2b..68c75b01e6f6df 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4974,20 +4974,35 @@ template <class Emitter> bool Compiler<Emitter>::visitIfStmt(const IfStmt *IS) {
LabelTy LabelEnd = this->getLabel();
if (!this->jumpFalse(LabelElse))
return false;
- if (!visitStmt(IS->getThen()))
- return false;
+ {
+ LocalScope<Emitter> ThenScope(this);
+ if (!visitStmt(IS->getThen()))
+ return false;
+ if (!ThenScope.destroyLocals())
+ return false;
+ }
if (!this->jump(LabelEnd))
return false;
this->emitLabel(LabelElse);
- if (!visitStmt(Else))
- return false;
+ {
+ LocalScope<Emitter> ElseScope(this);
+ if (!visitStmt(Else))
+ return false;
+ if (!ElseScope.destroyLocals())
+ return false;
+ }
this->emitLabel(LabelEnd);
} else {
LabelTy LabelEnd = this->getLabel();
if (!this->jumpFalse(LabelEnd))
return false;
- if (!visitStmt(IS->getThen()))
- return false;
+ {
+ LocalScope<Emitter> ThenScope(this);
+ if (!visitStmt(IS->getThen()))
+ return false;
+ if (!ThenScope.destroyLocals())
+ return false;
+ }
this->emitLabel(LabelEnd);
}
diff --git a/clang/test/AST/ByteCode/if.cpp b/clang/test/AST/ByteCode/if.cpp
index 540cb76fbaac3c..c48b2b8d378c85 100644
--- a/clang/test/AST/ByteCode/if.cpp
+++ b/clang/test/AST/ByteCode/if.cpp
@@ -76,3 +76,30 @@ namespace IfScope {
}
static_assert(foo() == 13, "");
}
+
+namespace IfScope2 {
+ struct __bit_iterator {
+ unsigned __ctz_;
+ };
+ constexpr void __fill_n_bool(__bit_iterator) {}
+
+ constexpr void fill_n(__bit_iterator __first) {
+ if (false)
+ __fill_n_bool(__first);
+ else
+ __fill_n_bool(__first);
+ }
+
+ struct bitset{
+ constexpr void reset() {
+ auto m = __bit_iterator(8);
+ fill_n(m);
+ }
+ };
+ consteval bool foo() {
+ bitset v;
+ v.reset();
+ return true;
+ }
+ static_assert(foo());
+}
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/59/builds/10234 Here is the relevant piece of the build log for the reference
|
Local branch amd-gfx 4b60f60 Merged main:6c42d0d7df55 into amd-gfx:5fd03520a677 Remote branch main acb7dfa [clang][bytecode] Create local scopes for if then/else statements (llvm#120852)
In case those aren't compound statements.