Commit Graph

18 Commits

Author SHA1 Message Date
Volodymyr Sapsai 6049e5437b [Sema] Emit -Winteger-overflow for arguments in function calls, ObjC messages.
rdar://problem/35539384

Reviewers: ahatanak, nicholas, rsmith, jkorous-apple

Reviewed By: jkorous-apple

Subscribers: cfe-commits, jkorous-apple

Differential Revision: https://reviews.llvm.org/D42938



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328671 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-27 21:29:05 +00:00
Richard Smith 74dbb6c51a Revert r301742, which caused us to try to evaluate all full-expressions.
Also add testcases for a bunch of expression forms that cause our evaluator to
crash. See PR33140 and PR32864 for crashes that this was causing.

This reverts r305287, which reverted r305239, which reverted r301742. The
previous revert claimed that buildbots were broken, but did not add any
testcases and the buildbots have lost all memory of what was wrong here.

Changes to test/OpenMP are not reverted; another change has triggered those
tests to change their output in the same way that r301742 did.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306346 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-26 23:19:32 +00:00
Diana Picus 68584d4a73 Revert "Revert r301742 which made ExprConstant checking apply to all full-exprs."
This reverts commit r305239 because it broke the buildbots (the
diag-flags.cpp test is failing).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305287 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-13 12:50:06 +00:00
Nick Lewycky c700ae6c9e Revert r301742 which made ExprConstant checking apply to all full-exprs.
This patch also exposed pre-existing bugs in clang, see PR32864 and PR33140#c3 .


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305239 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-12 21:59:18 +00:00
Nick Lewycky 7021b250b9 Revert r303316, a change to ExprConstant to evaluate function arguments.
The patch was itself correct but it uncovered other bugs which are going to be difficult to fix, per PR33140.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305233 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-12 21:15:44 +00:00
Nick Lewycky 7503060716 The constant expression evaluator should examine function arguments for non-constexpr function calls unless the EvalInfo says to stop.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303317 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-17 23:56:54 +00:00
Nick Lewycky 5ae2db8f76 Revert r301785 (and r301787) because they caused PR32864.
The fix is that ExprEvaluatorBase::VisitInitListExpr should handle transparent exprs instead of exprs with one element. Fixing that uncovers one testcase failure because the AST for "constexpr _Complex float test2 = {1};" is wrong (the _Complex prvalue should not be const-qualified), and a number of test failures in test/OpenMP where the captured stmt contains an InitListExpr that is in syntactic form.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301891 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-02 01:06:16 +00:00
Nick Lewycky c6deeaad91 Fix test that was incorrected merged between patches.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301787 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-01 02:20:06 +00:00
Nick Lewycky 02552ffef5 Handle expressions with non-literal types like ignored expressions if we are supposed to continue evaluating them.
Also fix a crash casting a derived nullptr to a virtual base.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301785 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-01 02:03:23 +00:00
Nick Lewycky f83586caa9 Remove Sema::CheckForIntOverflow, and instead check all full-expressions.
CheckForIntOverflow used to implement a whitelist of top-level expressions to
send to the constant expression evaluator, which handled many more expressions
than the CheckForIntOverflow whitelist did.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301742 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-29 09:33:46 +00:00
Nick Lewycky c1cea58321 In the expression evaluator, visit the index of an ArraySubscriptExpr even if we can't evaluate the base, if the evaluation mode tells us to continue evaluation.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301522 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-27 07:27:36 +00:00
Nick Lewycky 74bc51fffa In the expression evaluator, descend into both the true and false expressions of a ConditionalOperator when the condition can't be evaluated and we're in an evaluation mode that says we should continue evaluating.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301520 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-27 07:11:09 +00:00
Richard Trieu 803616f6bc Adjust tests to have consistent integer sizes.
Add a triple to the run lines so that integers will the same sizes across runs.
Also add a compile time check to ensure the assumptions about sizes are met.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265991 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-11 20:37:04 +00:00
Akira Hatanaka 3d46479781 [Sema] Issue a warning for integer overflow in nested struct initializer
r257357 fixed clang to warn on integer overflow in struct initializers.
However, it didn't warn when a struct had a nested initializer. This
commit makes changes in Sema::CheckForIntOverflow to handle nested
initializers.

For example:

struct s {
  struct t {
    unsigned x;
  } t;
} s = {
  {
    .x = 4 * 1024 * 1024 * 1024
  }
};

rdar://problem/23526454


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260360 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-10 06:06:06 +00:00
Akira Hatanaka 6b93d17661 [Sema] Issue a warning for integer overflow in struct initializer
Clang wasn't issuing a warning when compiling the following code:

struct s {
  unsigned x;
} s = {
  .x = 4 * 1024 * 1024 * 1024
};

rdar://problem/23399683

Differential Revision: http://reviews.llvm.org/D15097


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257357 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-11 17:22:01 +00:00
Richard Smith 42d13bb475 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.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254992 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-08 03:21:47 +00:00
Richard Smith 550a066d6e 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.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254574 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-03 01:36:22 +00:00
Josh Magee 749d8549d3 Catch more cases when diagnosing integer-constant-expression overflows.
When visiting AssignmentOps, keep evaluating after a failure (when possible) in
order to identify overflow in subexpressions.

Differential Revision: http://reviews.llvm.org/D1238


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@228202 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-04 21:50:20 +00:00