summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/const-eval.c
Commit message (Collapse)AuthorAgeFilesLines
* PR35214: don't crash if we see an array of unknown bound added to an empty ↵Richard Smith2017-11-151-0/+8
| | | | | | but invalid designator. llvm-svn: 318258
* Improve fix for PR28739Richard Smith2017-01-311-11/+6
| | | | | | | | | | | | | | | Don't try to map an APSInt addend to an int64_t in pointer arithmetic before bounds-checking it. This gives more consistent behavior (outside C++11, we consistently use 2s complement semantics for both pointer and integer overflow in constant expressions) and fixes some cases where in C++11 we would fail to properly check for out-of-bounds pointer arithmetic (if the 2s complement 64-bit overflow landed us back in-bounds). In passing, also fix some cases where we'd perform possibly-overflowing arithmetic on CharUnits (which have a signed underlying type) during constant expression evaluation. llvm-svn: 293595
* PR28739: Check that integer values fit into 64 bits before extracting them ↵Richard Smith2017-01-301-2/+14
| | | | | | | | | | | | | as 64 bit values for pointer arithmetic. This fixes various ways to tickle an assertion in constant expression evaluation when using __int128. Longer term, we need to figure out what should happen here: either any kind of overflow in offset calculation should result in a non-constant value or we should truncate to 64 bits. In C++11 onwards, we're effectively already checking for overflow because we strictly enforce array bounds checks, but even there some forms of overflow can slip past undetected. llvm-svn: 293568
* Explicitly permit undefined behavior in constant initializers for globalRichard Smith2015-12-081-1/+1
| | | | | | | | variables in C, in the cases where we can constant-fold it to a value regardless (such as floating-point division by zero and signed integer overflow). Strictly enforcing this rule breaks too much code. llvm-svn: 254992
* PR17381: Treat undefined behavior during expression evaluation as an unmodeledRichard Smith2015-12-031-1/+1
| | | | | | | | | | | | | | | | | | | | | side-effect, so that we don't allow speculative evaluation of such expressions during code generation. This caused a diagnostic quality regression, so fix constant expression diagnostics to prefer either the first "can't be constant folded" diagnostic or the first "not a constant expression" diagnostic depending on the kind of evaluation we're doing. This was always the intent, but didn't quite work correctly before. This results in certain initializers that used to be constant initializers to no longer be; in particular, things like: float f = 1e100; are no longer accepted in C. This seems appropriate, as such constructs would lead to code being executed if sanitizers are enabled. llvm-svn: 254574
* [AST] Don't crash when comparing incomplete objectDavid Majnemer2015-08-291-0/+4
| | | | | | | | | | We cannot tell if an object is past-the-end if its type is incomplete. Zero sized objects satisfy past-the-end criteria and our object might turn out to be such an object. This fixes PR24622. llvm-svn: 246359
* Make __builtin_object_size always answer correctlyGeorge Burgess IV2015-08-191-4/+0
| | | | | | | | | | | | | | | | | | __builtin_object_size would return incorrect answers for many uses where type=3. This fixes the inaccuracy by making us emit 0 instead of LLVM's objectsize intrinsic. Additionally, there are many cases where we would emit suboptimal (but correct) answers, such as when arrays are involved. This patch fixes some of these cases (please see new tests in test/CodeGen/object-size.c for specifics on which cases are improved) Resubmit of r245323 with PR24493 fixed. Patch mostly by Richard Smith. Differential Revision: http://reviews.llvm.org/D12000 This fixes PR15212. llvm-svn: 245403
* Revert r245323, it caused PR24493.Nico Weber2015-08-181-0/+4
| | | | llvm-svn: 245342
* Make __builtin_object_size always answer correctlyGeorge Burgess IV2015-08-181-4/+0
| | | | | | | | | | | | | | | | | __builtin_object_size would return incorrect answers for many uses where type=3. This fixes the inaccuracy by making us emit 0 instead of LLVM's objectsize intrinsic. Additionally, there are many cases where we would emit suboptimal (but correct) answers, such as when arrays are involved. This patch fixes some of these cases (please see new tests in test/CodeGen/object-size.c for specifics on which cases are improved) Patch mostly by Richard Smith. Differential Revision: http://reviews.llvm.org/D12000 This fixes PR15212. llvm-svn: 245323
* Fix PR21945: Crash in constant evaluator.Jonathan Roelofs2015-06-011-0/+3
| | | | | | Patch by Косов Евгений! llvm-svn: 238758
* PR16074, implement warnings to catch pointer to boolean true and pointer toRichard Trieu2014-02-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | null comparison when the pointer is known to be non-null. This catches the array to pointer decay, function to pointer decay and address of variables. This does not catch address of function since this has been previously used to silence a warning. Pointer to bool conversion is under -Wbool-conversion. Pointer to null comparison is under -Wtautological-pointer-compare, a sub-group of -Wtautological-compare. void foo() { int arr[5]; int x; // warn on these conditionals if (foo); if (arr); if (&x); if (foo == null); if (arr == null); if (&x == null); if (&foo); // no warning } llvm-svn: 202216
* Don't treat overflow in floating-point conversions as a hard error in ↵Eli Friedman2012-07-171-0/+3
| | | | | | constant evaluation. <rdar://problem/11874571>. llvm-svn: 160394
* Per Richard's comments on r154794, add the checks necessary to handle ↵Eli Friedman2012-04-161-0/+6
| | | | | | constant-folding relational comparisons safely in case the user is using -fwrapv or equivalent. llvm-svn: 154849
* Make constant evaluation for pointer comparisons work correctly for some ↵Eli Friedman2012-04-161-0/+4
| | | | | | uncommon cases. <rdar://problem/10962435>. llvm-svn: 154794
* Add test for a construct we currently reject, constant-evaluating a load ↵Eli Friedman2012-04-111-0/+4
| | | | | | 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. llvm-svn: 154564
* Fix a crash in the diangostic code in EvalConstant. PR12043.Eli Friedman2012-02-211-0/+5
| | | | llvm-svn: 151100
* constexpr: evaluate (bool)&x as true when x is a local variable or a temporary.Richard Smith2012-01-261-1/+1
| | | | llvm-svn: 149045
* When folding the size of a global scope VLA to a constant, require the arrayRichard Smith2011-12-071-2/+2
| | | | | | | 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. llvm-svn: 146000
* PR11391: Don't try to evaluate the LHS of a _Complex assignment as an rvalue.Richard Smith2011-11-161-0/+4
| | | | llvm-svn: 144799
* Fix PR11385: A pointer constant expression which has been cast via an integer isRichard Smith2011-11-161-1/+4
| | | | | | | not safely derived. Don't allow lvalue-to-rvalue conversions on the result of dereferencing such a pointer. llvm-svn: 144783
* Add missing casts to AST.Eli Friedman2011-11-121-0/+3
| | | | llvm-svn: 144455
* Constant expression evaluation: although we don't know whether a literal willRichard Smith2011-11-041-0/+3
| | | | | | | be at the same address as another object, we do know it won't alias a null pointer. llvm-svn: 143674
* When constant-folding, don't look at the initializer of a global const variableRichard Smith2011-11-011-0/+4
| | | | | | if it's marked as weak: that definition may not end up being used. llvm-svn: 143496
* Refactoring and test for r143360. Support for array rvalue to pointer decay isRichard Smith2011-10-311-0/+3
| | | | | | needed for C++11, and will follow later. llvm-svn: 143363
* Fix assert on constant expression evaluation of floating point increment.Richard Smith2011-10-301-0/+1
| | | | llvm-svn: 143320
* Don't crash if a GCC binary conditional is used in a constant expression on anRichard Smith2011-10-291-0/+3
| | | | | | integer-cast pointer value. llvm-svn: 143299
* Fix assertion in constant expression evaluation. The LHS of a floating-pointRichard Smith2011-10-281-0/+2
| | | | | | binary operator isn't an rvalue if it's an assignment operator. llvm-svn: 143250
* when compiling in a GNU mode (e.g. gnu99) treat VLAs with a size that can be ↵Chris Lattner2011-06-141-1/+1
| | | | | | | | | | 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 llvm-svn: 132983
* Fix tests to account for new warning "expected ';' at end of declaration ↵Carl Norum2011-03-071-1/+1
| | | | | | list". Sorry, folks! llvm-svn: 127188
* Properly do a float -> _Complex double conversion, fixes rdar://8875946.Argyrios Kyrtzidis2011-01-181-0/+6
| | | | llvm-svn: 123759
* fix PR7885, rejecting invalid uses of __builtin_constant_p.Chris Lattner2010-10-121-1/+1
| | | | llvm-svn: 116317
* PR7884: Fix the implementations of __real__ and __imag__ on real floats.Eli Friedman2010-08-141-2/+6
| | | | llvm-svn: 111080
* Make the "unused result" warning a warning about run-time behavior, soDouglas Gregor2010-07-151-1/+1
| | | | | | that we don't warn when there isn't going to be any computation anyway. llvm-svn: 108442
* Fix rdar://8139785 "implement warning on dead expression in comma operator"Argyrios Kyrtzidis2010-06-301-1/+1
| | | | | | | | | | 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'. llvm-svn: 107274
* Fix for PR6274: teach constant folding to evaluate __builtin_expect.Eli Friedman2010-02-131-0/+1
| | | | llvm-svn: 96054
* Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'.Daniel Dunbar2009-12-151-1/+1
| | | | | | | | | - 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). llvm-svn: 91446
* Add constant evaluation for comma operator with floating-point operand. FixesEli Friedman2009-11-161-0/+2
| | | | | | PR5449. llvm-svn: 88885
* Make ASTContext::getIntWidth return 1 for all boolean type variations, not ↵Sebastian Redl2009-11-051-0/+5
| | | | | | just for the unqualified, unaliased bool. llvm-svn: 86174
* PR4351: Add constant evaluation for constructs like "foo == NULL", where Eli Friedman2009-06-141-0/+2
| | | | | | foo has a constant address. llvm-svn: 73321
* PR4326: Handle constant evaluation for void* pointer subtraction Eli Friedman2009-06-041-0/+1
| | | | | | correctly. llvm-svn: 72886
* PR4097: add logic to Evaluate to handle pointer equality comparisons.Eli Friedman2009-04-281-0/+2
| | | | llvm-svn: 70317
* Add handling for complex->int, int->complex float, and float->complex Eli Friedman2009-04-221-0/+2
| | | | | | | int. Note that constant int->complex float and float->complex int casts were being miscompiled. llvm-svn: 69821
* Fix PR4027 + rdar://6808859, we were rejecting implicit casts ofChris Lattner2009-04-211-0/+6
| | | | | | aggregates even though we already accept explicit ones. Easy fix. llvm-svn: 69661
* Rename clang to clang-cc.Daniel Dunbar2009-03-241-1/+1
| | | | | | Tests and drivers updated, still need to shuffle dirs. llvm-svn: 67602
* Minor enhancements to Evaluate.Eli Friedman2009-03-231-0/+5
| | | | llvm-svn: 67503
* Fix invalid VLAs/VMs in Sema::ActOnVariableDeclarator, so that the variable ↵Anders Carlsson2009-02-281-0/+3
| | | | | | | | | | | 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. llvm-svn: 65725
* Fix obvious shortcoming in the implementations of Evaluate for Eli Friedman2009-02-281-0/+5
| | | | | | integer __real__ and __imag__. Not sure how I missed this. llvm-svn: 65677
* Evaluation of unary deref could call integer evaluator on non-integralDaniel Dunbar2009-02-211-0/+2
| | | | | | | expr; hilarity ensued. - PR3640. llvm-svn: 65234
* Add support for * (unary dereference) operator to ExprConstant.Eli Friedman2009-02-201-0/+2
| | | | llvm-svn: 65105
* Emit the correct diagnostics when we constant fold an array size to a ↵Anders Carlsson2009-02-191-0/+4
| | | | | | negative value. llvm-svn: 65023
OpenPOWER on IntegriCloud