-
Notifications
You must be signed in to change notification settings - Fork 103
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
Loop body should be emitted in different scope #1218
Comments
Makes sense to me! |
The same problem also exists for void test() {
while (int x = foo()) {
int y = foo();
use(x, y);
}
} ClangIR currently emits: cir.func @_Z4testv() extra(#fn_attr) {
cir.scope {
%0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init]
%1 = cir.alloca !s32i, !cir.ptr<!s32i>, ["y", init]
cir.while {
// ...
} do {
// ...
}
}
cir.return
} I actually expect it to be: cir.func @_Z4testv() extra(#fn_attr) {
cir.scope {
%0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init]
cir.while {
// ...
} do {
cir.scope {
%1 = cir.alloca !s32i, !cir.ptr<!s32i>, ["y", init]
// ...
}
}
}
cir.return
} A somehow unrelated issue is the |
This patch puts for-loop body, while-loop body, and do-while-loop body in nested scopes. Allocas in the loop body are now push down to the nested scope. Resolve llvm#1218 .
This patch puts for-loop body, while-loop body, and do-while-loop body in nested scopes. Allocas in the loop body are now push down to the nested scope. Resolve llvm#1218 .
In the comments of
CIRGenStmt.cpp
:clangir/clang/lib/CIR/CodeGen/CIRGenStmt.cpp
Lines 913 to 918 in 3189c0d
I believe the comment's statement is actually wrong. The referenced page says:
Thus in C++ the scope of statement should be in a scope nested within the scope of init-statement, but not in the same scope with init-statement.
For the following C++ code:
ClangIR currently emits the following CIR:
I actually expect it to be:
Note the difference of the places of the
alloca
operation for local variablex
.The text was updated successfully, but these errors were encountered: