Skip to content
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

wrong code at -O2 and -O3 on x86_64-linux-gnu #49005

Closed
zhendongsu opened this issue Mar 20, 2021 · 6 comments
Closed

wrong code at -O2 and -O3 on x86_64-linux-gnu #49005

zhendongsu opened this issue Mar 20, 2021 · 6 comments
Labels
bugzilla Issues migrated from bugzilla

Comments

@zhendongsu
Copy link

Bugzilla Link 49661
Resolution FIXED
Resolved on May 20, 2021 09:39
Version trunk
OS All
CC @LebedevRI,@RKSimon,@nikic,@rotateright,@oToToT
Fixed by commit(s) f34311c

Extended Description

[520] % clangtk -v
clang version 13.0.0 (https://github.com/llvm/llvm-project.git f860187)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /local/suz-local/opfuzz/bin
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@MX32
Selected multilib: .;@m64
[521] %
[521] % clangtk -Os small.c; ./a.out
[522] %
[522] % clangtk -O2 small.c
[523] % ./a.out
Segmentation fault
[524] %
[524] % cat small.c
static int *a[2][3][3], b, c;
int main() {
for (c = 0; c < 2; c++)
for (b = 0; b < 2; b++)
a[1][c][b] = a[0][0][0];
return 0;
}

@RKSimon
Copy link
Collaborator

RKSimon commented Mar 21, 2021

https://gcc.godbolt.org/z/xTv9PG

Seems to be an alignment issue

@​_ZL1a.1 = internal unnamed_addr global [3 x [3 x i32*]] zeroinitializer, align 16

define dso_local i32 @​main() local_unnamed_addr #​0 {
store <2 x i32*> zeroinitializer, <2 x i32*>* bitcast ([3 x [3 x i32*]]* @​_ZL1a.1 to <2 x i32*>), align 16
store <2 x i32
> zeroinitializer, <2 x i32*>* bitcast (i32** getelementptr inbounds ([3 x [3 x i32*]], [3 x [3 x i32*]]* @​_ZL1a.1, i64 0, i64 1, i64 0) to <2 x i32*>*), align 16 ; THIS ISN'T 16-BYTE ALIGNED
ret i32 0
}

@rotateright
Copy link
Contributor

This looks the same as bug 50253, but not making it a duplicate yet since I don't know anything about -globalopt.

Before that pass, we have:

@​c = internal unnamed_addr global i32 0, align 4
@​b = internal unnamed_addr global i32 0, align 4
@​a = internal unnamed_addr global [2 x [3 x [3 x i32*]]] zeroinitializer, align 16

; Function Attrs: nofree norecurse nosync nounwind ssp uwtable
define i32 @​main() local_unnamed_addr #​0 {
entry:
%0 = load i32*, i32** getelementptr inbounds ([2 x [3 x [3 x i32*]]], [2 x [3 x [3 x i32*]]]* @​a, i64 0, i64 0, i64 0, i64 0), align 16, !tbaa !​5
store i32* %0, i32** getelementptr inbounds ([2 x [3 x [3 x i32*]]], [2 x [3 x [3 x i32*]]]* @​a, i64 0, i64 1, i64 0, i64 0), align 8, !tbaa !​5
store i32* %0, i32** getelementptr inbounds ([2 x [3 x [3 x i32*]]], [2 x [3 x [3 x i32*]]]* @​a, i64 0, i64 1, i64 0, i64 1), align 16, !tbaa !​5
store i32* %0, i32** getelementptr inbounds ([2 x [3 x [3 x i32*]]], [2 x [3 x [3 x i32*]]]* @​a, i64 0, i64 1, i64 1, i64 0), align 16, !tbaa !​5
store i32* %0, i32** getelementptr inbounds ([2 x [3 x [3 x i32*]]], [2 x [3 x [3 x i32*]]]* @​a, i64 0, i64 1, i64 1, i64 1), align 8, !tbaa !​5
store i32 2, i32* @​c, align 4, !tbaa !​9
store i32 2, i32* @​b, align 4, !tbaa !​9
ret i32 0
}

And after:

@​a.1 = internal unnamed_addr global [3 x [3 x i32*]] zeroinitializer, align 16

; Function Attrs: nofree norecurse nosync nounwind ssp uwtable
define i32 @​main() local_unnamed_addr #​0 {
entry:
%b = alloca i32, align 4
store i32 0, i32* %b, align 4
%c = alloca i32, align 4
store i32 0, i32* %c, align 4
store i32* null, i32** getelementptr inbounds ([3 x [3 x i32*]], [3 x [3 x i32*]]* @​a.1, i32 0, i64 0, i64 0), align 8, !tbaa !​5
store i32* null, i32** getelementptr inbounds ([3 x [3 x i32*]], [3 x [3 x i32*]]* @​a.1, i32 0, i64 0, i64 1), align 16, !tbaa !​5
store i32* null, i32** getelementptr inbounds ([3 x [3 x i32*]], [3 x [3 x i32*]]* @​a.1, i32 0, i64 1, i64 0), align 16, !tbaa !​5
store i32* null, i32** getelementptr inbounds ([3 x [3 x i32*]], [3 x [3 x i32*]]* @​a.1, i32 0, i64 1, i64 1), align 8, !tbaa !​5
store i32 2, i32* %c, align 4, !tbaa !​9
store i32 2, i32* %b, align 4, !tbaa !​9
ret i32 0
}

@rotateright
Copy link
Contributor

@rotateright
Copy link
Contributor

Should be fixed with:
https://reviews.llvm.org/rGf34311c4024d

@rotateright
Copy link
Contributor

*** Bug llvm/llvm-bugzilla-archive#50253 has been marked as a duplicate of this bug. ***

@rotateright
Copy link
Contributor

mentioned in issue llvm/llvm-bugzilla-archive#50253

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

3 participants