If the value of __builtin_constant_p is constant, 1 is returned even when there is a side effect. This is a regression in Clang 9. Testcase: #include <stdio.h> int main (void) { int c, i = 0; c = __builtin_constant_p ((i++, 0)); printf ("%d %d\n", c, i); return 0; } which outputs "1 0" instead of "0 0" with: clang version 9.0.0-1 (tags/RELEASE_900/final) Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin (Debian package clang-9 1:9-1). Note: This makes one test of GNU MPFR fail (tcmp_ui) and can affect code using MPFR, when this user code is built with Clang 9.
Also note that the example static const int table[] = { __builtin_constant_p (EXPRESSION) ? (EXPRESSION) : -1, /* ... */ }; from the GCC manual fails to build if EXPRESSION is (i++, 0) like in my testcase.
This appears to be fixed in trunk: https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(fontScale:14,j:1,lang:c%2B%2B,selection:(endColumn:2,endLineNumber:8,positionColumn:2,positionLineNumber:8,selectionStartColumn:2,selectionStartLineNumber:8,startColumn:2,startLineNumber:8),source:'extern+%22C%22+int+printf(const+char+*,+...)%3B%0Aint+main+(void)%0A%7B%0A++int+c,+i+%3D+0%3B%0A++c+%3D+__builtin_constant_p+((i%2B%2B,+0))%3B%0A++printf+(%22%25d+%25d%5Cn%22,+c,+i)%3B%0A++return+0%3B%0A%7D'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:clang_trunk,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'1',trim:'1'),fontScale:14,j:1,lang:c%2B%2B,libs:!(),options:'-O2',selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'x86-64+clang+(trunk)+(Editor+%231,+Compiler+%231)+C%2B%2B',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4
In Debian, this bug no longer occurs at least in clang-9 1:9.0.1-12.