diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-12-03 01:36:22 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-12-03 01:36:22 +0000 |
| commit | 0c6124ba82063b05b9c85b63bb29ec354aa1be0b (patch) | |
| tree | c5cb08e6eb95fe213116ac9bbad149a05d31577a /clang/test/SemaCXX | |
| parent | a30cee627201032bc7ea66808d057d97f52b852f (diff) | |
| download | bcm5719-llvm-0c6124ba82063b05b9c85b63bb29ec354aa1be0b.tar.gz bcm5719-llvm-0c6124ba82063b05b9c85b63bb29ec354aa1be0b.zip | |
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
Diffstat (limited to 'clang/test/SemaCXX')
| -rw-r--r-- | clang/test/SemaCXX/constant-expression-cxx11.cpp | 7 | ||||
| -rw-r--r-- | clang/test/SemaCXX/constexpr-printing.cpp | 4 |
2 files changed, 6 insertions, 5 deletions
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp index 794932df409..7b9d0150e1e 100644 --- a/clang/test/SemaCXX/constant-expression-cxx11.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp @@ -327,7 +327,7 @@ struct Str { }; extern char externalvar[]; -constexpr bool constaddress = (void *)externalvar == (void *)0x4000UL; // expected-error {{must be initialized by a constant expression}} +constexpr bool constaddress = (void *)externalvar == (void *)0x4000UL; // expected-error {{must be initialized by a constant expression}} expected-note {{reinterpret_cast}} constexpr bool litaddress = "foo" == "foo"; // expected-error {{must be initialized by a constant expression}} expected-warning {{unspecified}} static_assert(0 != "foo", ""); @@ -1874,10 +1874,9 @@ namespace NeverConstantTwoWays { 0; } - // FIXME: We should diagnose the cast to long here, not the division by zero. constexpr int n = // expected-error {{must be initialized by a constant expression}} - (int *)(long)&n == &n ? - 1 / 0 : // expected-warning {{division by zero}} expected-note {{division by zero}} + (int *)(long)&n == &n ? // expected-note {{reinterpret_cast}} + 1 / 0 : // expected-warning {{division by zero}} 0; } diff --git a/clang/test/SemaCXX/constexpr-printing.cpp b/clang/test/SemaCXX/constexpr-printing.cpp index e545f45d601..7f6a9c6a82f 100644 --- a/clang/test/SemaCXX/constexpr-printing.cpp +++ b/clang/test/SemaCXX/constexpr-printing.cpp @@ -90,10 +90,12 @@ constexpr wchar_t wc = get(L"test\0\\\"\t\a\b\234\u1234\xffffffff"); // \ constexpr char32_t c32_err = get(U"\U00110000"); // expected-error {{invalid universal character}} +#define fold(x) (__builtin_constant_p(x) ? (x) : (x)) + typedef decltype(sizeof(int)) LabelDiffTy; constexpr LabelDiffTy mulBy3(LabelDiffTy x) { return x * 3; } // expected-note {{subexpression}} void LabelDiffTest() { - static_assert(mulBy3((LabelDiffTy)&&a-(LabelDiffTy)&&b) == 3, ""); // expected-error {{constant expression}} expected-note {{call to 'mulBy3(&&a - &&b)'}} + static_assert(mulBy3(fold((LabelDiffTy)&&a-(LabelDiffTy)&&b)) == 3, ""); // expected-error {{constant expression}} expected-note {{call to 'mulBy3(&&a - &&b)'}} a:b:return; } |

