Commit Graph

13 Commits

Author SHA1 Message Date
Richard Smith ce8eca578d Explicitly permit undefined behavior in constant initializers for global
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
2015-12-08 03:21:47 +00:00
Richard Smith 0c6124ba82 PR17381: Treat undefined behavior during expression evaluation as an unmodeled
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
2015-12-03 01:36:22 +00:00
Charles Li 430db1e717 [Tests] Modified Lit Tests to be C++11 compatibile
This 2nd patch should not change the test results, but it is useful if clang's
default C++ language is ever changed from gnu++98.

llvm-svn: 246183
2015-08-27 18:49:15 +00:00
Fariborz Jahanian c694e693b0 Patch to warn on interger overflow in presence of
implicit casts. Reviewed by Reid Kleckner.
rdar://18405357

llvm-svn: 219712
2014-10-14 20:27:05 +00:00
Fariborz Jahanian 1c150a0d0d c: Also chek for integer overflow for '%' operator.
llvm-svn: 177163
2013-03-15 17:03:56 +00:00
Fariborz Jahanian 352eeafa0a c: add the missing binary operatory when checking
for integer overflow. // rdar://13423975

llvm-svn: 177162
2013-03-15 16:36:04 +00:00
Fariborz Jahanian d0ed6c249d Add space after ';'.
llvm-svn: 173462
2013-01-25 17:47:49 +00:00
Fariborz Jahanian 740396437b Improve diagnsotic further on integer overflow.
llvm-svn: 173461
2013-01-25 17:19:07 +00:00
Fariborz Jahanian ee19ceb409 Fixes text of diagnostics in integer overflow patch.
llvm-svn: 173388
2013-01-24 23:24:32 +00:00
Fariborz Jahanian e735ff93e8 Patch to check for integer overflow. It has been
commented on and approved by Richard Smith.

llvm-svn: 173377
2013-01-24 22:11:45 +00:00
Fariborz Jahanian 70ae634f87 Improve diagnostic per Richard's suggestion
(which may yet change if we move the diagnostic
 outside case value).

llvm-svn: 172242
2013-01-11 19:33:54 +00:00
Fariborz Jahanian 941827931e Provide a better warning when case value overflows.
// rdar://11577384

llvm-svn: 172102
2013-01-10 20:26:42 +00:00
Fariborz Jahanian 8b115b7872 Issue warning when case value is too large to fit
in case condition type. // rdar://11577384.
Test is conditionalized on x86_64-apple triple as
I am not sure if the INT_MAX/LONG_MAX values in the test
will pass this test for other hosts.

llvm-svn: 172016
2013-01-09 23:04:56 +00:00