Skip to content

[clang] Miscompilation at -Os #119646

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

Closed
cardigan1008 opened this issue Dec 12, 2024 · 3 comments
Closed

[clang] Miscompilation at -Os #119646

cardigan1008 opened this issue Dec 12, 2024 · 3 comments

Comments

@cardigan1008
Copy link

This code prints 1 at -Os and 0 at -O0/1/2/3:

int printf(const char *, ...);
long a, b = 208;
short c;
long(d)(long e) { return (a && e && 2036854775807 / e) * a; }
void f(long *e) {
  if (d(c | (*e = b || 0)))
    for (;;)
      ;
}
int main() {
  long *g = &b;
  *g = 0;
  f(&b);
  printf("%d\n", (int)b);
}

Compiler Explorer: https://godbolt.org/z/vPvna9s5Y

Bisected to ebe741f which was committed by @haopliu

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Dec 12, 2024
@EugeneZelenko EugeneZelenko added miscompilation llvm:transforms and removed clang Clang issues not falling into any other category labels Dec 12, 2024
@pinskia
Copy link

pinskia commented Dec 12, 2024

Reduced down to just:

int b = 208;
[[gnu::noinline]]
void f(int *e, int a) {
  *e = !!b;
  if (a)
    __builtin_trap();
}
int main(void) {
  b = 0;
  f(&b, 0);
  if (b != 0)
    __builtin_trap();
}

@nikic
Copy link
Contributor

nikic commented Dec 12, 2024

I think the problem here is basically the same as the one in #119116 (comment).

hubot pushed a commit to gcc-mirror/gcc that referenced this issue Jan 3, 2025
…init=

This testcase came up in a recent LLVM bug report [0] for DSE vs
-ftrivial-auto-var-init=. Add it to our testsuite given that area
could do with better coverage.

[0] llvm/llvm-project#119646

gcc/testsuite/ChangeLog:

	* gcc.dg/torture/dse-trivial-auto-var-init.c: New test.

Co-authored-by: Andrew Pinski <[email protected]>
@haopliu
Copy link
Contributor

haopliu commented Jan 23, 2025

Fixed the problem in #120044.

Will reenable the DSE improvement in #124058

@nikic nikic closed this as completed Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants