summaryrefslogtreecommitdiff
path: root/test/CodeGen/builtin-constant-p.c
Commit message (Collapse)AuthorAgeFilesLines
* Improve __builtin_constant_p loweringJoerg Sonnenberger2019-10-131-81/+46
| | | | | | | | | | | | | | | | | __builtin_constant_p used to be short-cut evaluated to false when building with -O0. This is undesirable as it means that constant folding in the front-end can give different results than folding in the back-end. It can also create conditional branches on constant conditions that don't get folded away. With the pending improvements to the llvm.is.constant handling on the LLVM side, the short-cut is no longer useful. Adjust various codegen tests to not depend on the short-cut or the backend optimisations. Differential Revision: https://reviews.llvm.org/D67638 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@374742 91177308-0d34-0410-b5e6-96231b3b80d8
* Reinstate r359059, reverted in r359361, with a fix to properly preventRichard Smith2019-04-271-0/+8
| | | | | | | | | | | | | | | | | | | | | | | us emitting the operand of __builtin_constant_p if it has side-effects. Original commit message: Fix interactions between __builtin_constant_p and constexpr to match current trunk GCC. GCC permits information from outside the operand of __builtin_constant_p (but in the same constant evaluation context) to be used within that operand; clang now does so too. A few other minor deviations from GCC's behavior showed up in my testing and are also fixed (matching GCC): * Clang now supports nullptr_t as the argument type for __builtin_constant_p * Clang now returns true from __builtin_constant_p if called with a null pointer * Clang now returns true from __builtin_constant_p if called with an integer cast to pointer type git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359367 91177308-0d34-0410-b5e6-96231b3b80d8
* Emit ASM input in a constant contextBill Wendling2018-12-181-0/+11
| | | | | | | | | | | | | | | | | Summary: Some ASM input constraints (e.g., "i" and "n") require immediate values. At O0, very few code transformations are performed. So if we cannot resolve to an immediate when emitting the ASM input we shouldn't delay its processing. Reviewers: rsmith, efriedma Reviewed By: efriedma Subscribers: rehana, efriedma, craig.topper, jyknight, cfe-commits Differential Revision: https://reviews.llvm.org/D55616 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349561 91177308-0d34-0410-b5e6-96231b3b80d8
* Specify constant context in constant emitterBill Wendling2018-12-011-0/+168
| | | | | | | | The constant emitter may need to evaluate the expression in a constant context. For exasmple, global initializer lists. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348070 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert r347417 "Re-Reinstate 347294 with a fix for the failures."Fangrui Song2018-11-301-159/+0
| | | | | | | | | | Kept the "indirect_builtin_constant_p" test case in test/SemaCXX/constant-expression-cxx1y.cpp while we are investigating why the following snippet fails: extern char extern_var; struct { int a; } a = {__builtin_constant_p(extern_var)}; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348039 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert r348029. I was git-ing and jumped the gun.Bill Wendling2018-11-301-11/+0
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348032 91177308-0d34-0410-b5e6-96231b3b80d8
* We're in a constant context in the ConstantEmitter.Bill Wendling2018-11-301-0/+11
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348029 91177308-0d34-0410-b5e6-96231b3b80d8
* Re-commit r347417 "Re-Reinstate 347294 with a fix for the failures."Hans Wennborg2018-11-281-0/+159
| | | | | | | This was reverted in r347656 due to me thinking it caused a miscompile of Chromium. Turns out it was the Chromium code that was broken. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347756 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert r347417 "Re-Reinstate 347294 with a fix for the failures."Hans Wennborg2018-11-271-159/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This caused a miscompile in Chrome (see crbug.com/908372) that's illustrated by this small reduction: static bool f(int *a, int *b) { return !__builtin_constant_p(b - a) || (!(b - a)); } int arr[] = {1,2,3}; bool g() { return f(arr, arr + 3); } $ clang -O2 -S -emit-llvm a.cc -o - g() should return true, but after r347417 it became false for some reason. This also reverts the follow-up commits. r347417: > Re-Reinstate 347294 with a fix for the failures. > > Don't try to emit a scalar expression for a non-scalar argument to > __builtin_constant_p(). > > Third time's a charm! r347446: > The result of is.constant() is unsigned. r347480: > A __builtin_constant_p() returns 0 with a function type. r347512: > isEvaluatable() implies a constant context. > > Assume that we're in a constant context if we're asking if the expression can > be compiled into a constant initializer. This fixes the issue where a > __builtin_constant_p() in a compound literal was diagnosed as not being > constant, even though it's always possible to convert the builtin into a > constant. r347531: > A "constexpr" is evaluated in a constant context. Make sure this is reflected > if a __builtin_constant_p() is a part of a constexpr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347656 91177308-0d34-0410-b5e6-96231b3b80d8
* isEvaluatable() implies a constant context.Bill Wendling2018-11-241-0/+3
| | | | | | | | | | | Assume that we're in a constant context if we're asking if the expression can be compiled into a constant initializer. This fixes the issue where a __builtin_constant_p() in a compound literal was diagnosed as not being constant, even though it's always possible to convert the builtin into a constant. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347512 91177308-0d34-0410-b5e6-96231b3b80d8
* A __builtin_constant_p() returns 0 with a function type.Bill Wendling2018-11-221-0/+26
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347480 91177308-0d34-0410-b5e6-96231b3b80d8
* The result of is.constant() is unsigned.Bill Wendling2018-11-221-0/+130
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347446 91177308-0d34-0410-b5e6-96231b3b80d8