-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[Clang] [CodeGen] Wrong code generation for extern reference
#127475
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
Comments
Reduced: https://godbolt.org/z/TMMhcEo7s |
@llvm/issue-subscribers-clang-codegen Author: ykiko (16bit-ykiko)
Minimal Reproducible Example:
/// src.cpp
#include <vector>
struct S {
std::vector<int> c;
};
static S ls = {{1, 2, 3}};
S& s = ls;
/// main.cpp
#include <cstdio>
#include <vector>
struct S {
std::vector<int> c;
};
extern S& s;
int main() {
for (size_t i = 0; i < s.c.size(); i++) {
printf("aaa\n");
}
for (auto& i : s.c) {
printf("bbb\n");
}
return 0;
} |
I use git bisect and find commit 0a9c08c , which emits store ptr getelementptr (i8, ptr @s, i64 1), ptr %__range1, align 8
%3 = load ptr, ptr %__range1, align 8
%call1 = call ptr @_ZNSt6vectorIiSaIiEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #1 then commit is c9637af (which try to fix 0a9c08c #95474 ) , which emits: store ptr @s, ptr %__range1, align 8
%3 = load ptr, ptr %__range1, align 8
%call1 = call ptr @_ZNSt6vectorIiSaIiEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #1 |
Related code: llvm-project/clang/lib/CodeGen/CGDecl.cpp Lines 1988 to 1992 in fb29f19
|
@llvm/issue-subscribers-clang-frontend Author: ykiko (16bit-ykiko)
Minimal Reproducible Example:
/// src.cpp
#include <vector>
struct S {
std::vector<int> c;
};
static S ls = {{1, 2, 3}};
S& s = ls;
/// main.cpp
#include <cstdio>
#include <vector>
struct S {
std::vector<int> c;
};
extern S& s;
int main() {
for (size_t i = 0; i < s.c.size(); i++) {
printf("aaa\n");
}
for (auto& i : s.c) {
printf("bbb\n");
}
return 0;
} |
…ateAsInitializer` (#128409) It is an alternative to llvm/llvm-project#127525. Close llvm/llvm-project#127475.
…lizer` (llvm#128409) It is an alternative to llvm#127525. Close llvm#127475.
…lizer` (#128409) It is an alternative to llvm/llvm-project#127525. Close llvm/llvm-project#127475.
…lizer` (llvm#128409) It is an alternative to llvm#127525. Close llvm#127475.
…ateAsInitializer` (#128409) It is an alternative to llvm/llvm-project#127525. Close llvm/llvm-project#127475.
Minimal Reproducible Example:
https://godbolt.org/z/W1YoYsMYh
The text was updated successfully, but these errors were encountered: