aboutsummaryrefslogtreecommitdiff
path: root/test/Sema/const-eval.c
AgeCommit message (Collapse)Author
2012-07-17Don't treat overflow in floating-point conversions as a hard error in ↵Eli Friedman
constant evaluation. <rdar://problem/11874571>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160394 91177308-0d34-0410-b5e6-96231b3b80d8
2012-04-16Per Richard's comments on r154794, add the checks necessary to handle ↵Eli Friedman
constant-folding relational comparisons safely in case the user is using -fwrapv or equivalent. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154849 91177308-0d34-0410-b5e6-96231b3b80d8
2012-04-16Make constant evaluation for pointer comparisons work correctly for some ↵Eli Friedman
uncommon cases. <rdar://problem/10962435>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154794 91177308-0d34-0410-b5e6-96231b3b80d8
2012-04-11Add test for a construct we currently reject, constant-evaluating a load ↵Eli Friedman
from a constant string. Given that gcc doesn't accept this, we should continue to not accept it, even though it was accidentally supported by clang for a brief period. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154564 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-21Fix a crash in the diangostic code in EvalConstant. PR12043.Eli Friedman
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151100 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-26constexpr: evaluate (bool)&x as true when x is a local variable or a temporary.Richard Smith
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149045 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-07When folding the size of a global scope VLA to a constant, require the arrayRichard Smith
bound to not have side effects(!). Add constant-folding support for expressions of void type, to ensure that we can still fold ((void)0, 1) as an array bound. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146000 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-16PR11391: Don't try to evaluate the LHS of a _Complex assignment as an rvalue.Richard Smith
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144799 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-16Fix PR11385: A pointer constant expression which has been cast via an integer isRichard Smith
not safely derived. Don't allow lvalue-to-rvalue conversions on the result of dereferencing such a pointer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144783 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-12Add missing casts to AST.Eli Friedman
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144455 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-04Constant expression evaluation: although we don't know whether a literal willRichard Smith
be at the same address as another object, we do know it won't alias a null pointer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143674 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-01When constant-folding, don't look at the initializer of a global const variableRichard Smith
if it's marked as weak: that definition may not end up being used. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143496 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-31Refactoring and test for r143360. Support for array rvalue to pointer decay isRichard Smith
needed for C++11, and will follow later. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143363 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-30Fix assert on constant expression evaluation of floating point increment.Richard Smith
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143320 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-29Don't crash if a GCC binary conditional is used in a constant expression on anRichard Smith
integer-cast pointer value. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143299 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-28Fix assertion in constant expression evaluation. The LHS of a floating-pointRichard Smith
binary operator isn't an rvalue if it's an assignment operator. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143250 91177308-0d34-0410-b5e6-96231b3b80d8
2011-06-14when compiling in a GNU mode (e.g. gnu99) treat VLAs with a size that can be ↵Chris Lattner
folded to a constant as constant size arrays. This has slightly different semantics in some insane cases, but allows us to accept some constructs that GCC does. Continue to be pedantic in -std=c99 and other modes. This addressed rdar://8733881 - error "variable-sized object may not be initialized"; g++ accepts same code git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@132983 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-07Fix tests to account for new warning "expected ';' at end of declaration ↵Carl Norum
list". Sorry, folks! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127188 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-18Properly do a float -> _Complex double conversion, fixes rdar://8875946.Argyrios Kyrtzidis
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123759 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-12fix PR7885, rejecting invalid uses of __builtin_constant_p.Chris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116317 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-14PR7884: Fix the implementations of __real__ and __imag__ on real floats.Eli Friedman
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111080 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-15Make the "unused result" warning a warning about run-time behavior, soDouglas Gregor
that we don't warn when there isn't going to be any computation anyway. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108442 91177308-0d34-0410-b5e6-96231b3b80d8
2010-06-30Fix rdar://8139785 "implement warning on dead expression in comma operator"Argyrios Kyrtzidis
As a bonus, fix the warning for || and && operators; it was emitted even if one of the operands had side effects, e.g: x || test_logical_foo1(); emitted a bogus "expression result unused" for 'x'. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107274 91177308-0d34-0410-b5e6-96231b3b80d8
2010-02-13Fix for PR6274: teach constant folding to evaluate __builtin_expect.Eli Friedman
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96054 91177308-0d34-0410-b5e6-96231b3b80d8
2009-12-15Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'.Daniel Dunbar
- This is designed to make it obvious that %clang_cc1 is a "test variable" which is substituted. It is '%clang_cc1' instead of '%clang -cc1' because it can be useful to redefine what gets run as 'clang -cc1' (for example, to set a default target). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91446 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-16Add constant evaluation for comma operator with floating-point operand. FixesEli Friedman
PR5449. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88885 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-05Make ASTContext::getIntWidth return 1 for all boolean type variations, not ↵Sebastian Redl
just for the unqualified, unaliased bool. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86174 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-14PR4351: Add constant evaluation for constructs like "foo == NULL", where Eli Friedman
foo has a constant address. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73321 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-04PR4326: Handle constant evaluation for void* pointer subtraction Eli Friedman
correctly. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72886 91177308-0d34-0410-b5e6-96231b3b80d8
2009-04-28PR4097: add logic to Evaluate to handle pointer equality comparisons.Eli Friedman
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70317 91177308-0d34-0410-b5e6-96231b3b80d8
2009-04-22Add handling for complex->int, int->complex float, and float->complex Eli Friedman
int. Note that constant int->complex float and float->complex int casts were being miscompiled. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69821 91177308-0d34-0410-b5e6-96231b3b80d8
2009-04-21Fix PR4027 + rdar://6808859, we were rejecting implicit casts ofChris Lattner
aggregates even though we already accept explicit ones. Easy fix. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69661 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-24Rename clang to clang-cc.Daniel Dunbar
Tests and drivers updated, still need to shuffle dirs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67602 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-23Minor enhancements to Evaluate.Eli Friedman
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67503 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-28Fix invalid VLAs/VMs in Sema::ActOnVariableDeclarator, so that the variable ↵Anders Carlsson
will have the right type by the time the initializer is checked. This ensures that code like int a[(int)(1.0 / 1.0) = { 1 } will work. Eli, please review. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65725 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-28Fix obvious shortcoming in the implementations of Evaluate for Eli Friedman
integer __real__ and __imag__. Not sure how I missed this. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65677 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-21Evaluation of unary deref could call integer evaluator on non-integralDaniel Dunbar
expr; hilarity ensued. - PR3640. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65234 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-20Add support for * (unary dereference) operator to ExprConstant.Eli Friedman
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65105 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-19Emit the correct diagnostics when we constant fold an array size to a ↵Anders Carlsson
negative value. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65023 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-19Make sure to check the value of the constant expression, as suggested by Daniel.Anders Carlsson
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65021 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-19Handle the GNU void* and function pointer arithmetic extensions for constant ↵Anders Carlsson
expressions as well. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65013 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-18isICE was evaluating ?: incorrectly with missing-gcc-LHS extension.Daniel Dunbar
Add assert to isICE that, on success, result must be the same as EvaluateAsInt()... this enforces a minimum level of sanity. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64865 91177308-0d34-0410-b5e6-96231b3b80d8
2009-01-24Fix invalid evaluation of _Complex float (real & imaginary parts hadDaniel Dunbar
mismatched semantics). - Enforce this in APValue. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62924 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-24The address of a variable is only constant if the variable has global storage.Anders Carlsson
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59939 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-24Fix bug in the constant evaluator. Fixes PR3115.Anders Carlsson
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59938 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-13Fix for crash issues with comma operators with a void first operand, and Eli Friedman
some more bullet-proofing/enhancements for tryEvaluate. This shouldn't cause any behavior changes except for handling cases where we were crashing before and being able to evaluate a few more cases in tryEvaluate. This should settle the minor mess surrounding r59196. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59224 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-13Backout of r59196, plus a new ICE test. Sorry if this is a Eli Friedman
little rude; I figure it's cleaner to just back this out now so it doesn't get forgotten or mixed up with other checkins. The modification to isICE is simply wrong; I've added a test that the change to isICE breaks. I'm pretty sure the modification to tryEvaluate is also wrong. At the very least, there's some serious miscommunication going on here, as this is going in exactly the opposite direction of r59105. My understanding is that tryEvaluate is not supposed to care about side effects. That said, a lot of the clients to tryEvaluate are expecting it to enforce a no-side-effects policy, so we probably need another method that provides that guarantee. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59212 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-13Fix bug in constant evaluation exposed by 176.gcc.Daniel Dunbar
- Evaluation of , operator used bogus assumption that LHS could be evaluated as an integral expression even though its type is unspecified. This change is making isICE very permissive of the LHS in non-evaluated contexts because it is not clear what predicate we would use to reject code here. The standard didn't offer me any guidance; opinions? git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59196 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-12Some additions to tryEvaluate I've had sitting around for a while.Eli Friedman
This pushes it a lot closer to being able to deal with most of the stuff CodeGen's constant expression evaluator knows how to deal with. This also fixes PR3003. The test could possibly use some improvement, but this'll work for now. Test 6 is inspired by PR3003; the other tests are mostly just designed to exercise the new code. The reason for the funny structure of the tests is that type fixing for arrays inside of structs is the only place in Sema that calls tryEvaluate, at least for the moment. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59125 91177308-0d34-0410-b5e6-96231b3b80d8