https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128002

            Bug ID: 128002
           Summary: wrong code with -O0 -fsanitize=address for an
                    address-taken parameter used in a nested function
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kyuwoncho18 at gmail dot com
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org
  Target Milestone: ---
            Target: x86_64-pc-linux-gnu

__attribute__((noipa)) int f(int x) {
  int *p = &x;
  int get(void) { return x; }
  return *p + get();
}
int main(void) {
  if (f(1) != 2)
    __builtin_abort();
}

godbolt: https://godbolt.org/z/PbcaMb3bv

With -O0, or with -O1/-O2 -fsanitize=address, f(1) returns 2 and the program
exits normally, but with -O0 -fsanitize=address f(1) does not return 2 and the
program aborts.

Disclaimer: This test case was generated by a fuzzer, and the report was
written with LLM assistance.

Reply via email to