[llvm-bugs] [Bug 48666] New: Spurious "expression with side effects has no effect in an unevaluated context" warning when VLA

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jan 5 09:32:57 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=48666

            Bug ID: 48666
           Summary: Spurious "expression with side effects has no effect
                    in an unevaluated context" warning when VLA
           Product: clang
           Version: 11.0
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: cuoq at trust-in-soft.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Consider the C compilation unit:

int Y, Z;

void f(int n) {
  long u[n];
  Y = sizeof *(Z=1, &u);
}

Clang warns that the side-effect “Z=1” will have no effect because it's an
unevaluated context, but actually, u is a VLA, and in this case side-effects
happen. Note that the code generated by Clang is correct, it is only the
warning that should not be emitted:

<source>:5:14: warning: expression with side effects has no effect in an
unevaluated context [-Wunevaluated-expression]
  Y = sizeof *(Z=1, &u);
             ^
1 warning generated.
Compiler returned: 0

Generated code with -O:

f:                                      # @f
        movl    $1, Z(%rip)
        shll    $3, %edi
        movl    %edi, Y(%rip)
        retq

Compiler Explorer link: https://gcc.godbolt.org/z/PG9cd9

The relevant C17 clause: https://cigix.me/c17#6.5.3.4.p2

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210105/9d44d201/attachment.html>


More information about the llvm-bugs mailing list