New user self-registration is disabled due to spam. For an account please email bugs-admin@lists.llvm.org with your e-mail address and full name.

Bug 43557 - __builtin_constant_p returns 1 instead of 0 when there is a side effect
Summary: __builtin_constant_p returns 1 instead of 0 when there is a side effect
Status: RESOLVED WORKSFORME
Alias: None
Product: new-bugs
Classification: Unclassified
Component: new bugs (show other bugs)
Version: 9.0
Hardware: PC Linux
: P release blocker
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-04 01:51 PDT by Vincent Lefevre
Modified: 2021-05-11 14:26 PDT (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vincent Lefevre 2019-10-04 01:51:16 PDT
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.
Comment 1 Vincent Lefevre 2019-10-04 02:09:37 PDT
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.
Comment 3 Vincent Lefevre 2020-06-16 09:34:22 PDT
In Debian, this bug no longer occurs at least in clang-9 1:9.0.1-12.