| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
|
|
|
| |
someone thought all the bits would be value bits in this case.
Also fix the wording of the warning -- it claimed that the width of 'bool' is
8, which is not correct; the width is 1 bit, whereas the size is 8 bits in our
implementation.
llvm-svn: 248435
|
|
|
|
|
|
|
|
|
|
|
|
| |
Summary: Implement DR262 (for C). This patch will mainly affect bitfields of type _Bool
Reviewers: fraggamuffin, rsmith
Subscribers: hubert.reinterpretcast, cfe-commits
Differential Revision: http://reviews.llvm.org/D10018
llvm-svn: 247618
|
|
|
|
|
|
| |
pointer to an RVO construction of a returned object.
llvm-svn: 246263
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
r235046 turned "extern __declspec(selectany) int a;" from a declaration into
a definition to fix PR23242 (required for compatibility with mc.exe output).
However, this broke parsing Windows headers: A d3d11 headers contain something
like
struct SomeStruct {};
extern const __declspec(selectany) SomeStruct some_struct;
This is now a definition, and const objects either need an explicit default
ctor or an initializer so this errors out with
d3d11.h(1065,48) :
error: default initialization of an object of const type
'const CD3D11_DEFAULT' without a user-provided default constructor
(cl.exe just doesn't implement this rule, independent of selectany.)
To work around this, weaken this error into a warning for selectany decls
in microsoft mode, and recover with zero-initialization.
Doing this is a bit hairy since it adds a fixit on an error emitted
by InitializationSequence – this means it needs to build a correct AST, which
in turn means InitializationSequence::Failed() cannot return true when this
fixit is applied. As a workaround, the patch adds a fixit member to
InitializationSequence, and InitializationSequence::Perform() prints the
diagnostic if the fixit member is set right after its call to Diagnose.
That function is usually called when InitializationSequences are used –
InitListChecker::PerformEmptyInit() doesn't call it, but the InitListChecker
case never performs default-initialization, so this is technically OK.
This is the alternative, original fix for PR20208 that got reviewed in the
thread "[patch] Improve diagnostic on default-initializing const variables
(PR20208)". This change basically reverts r213725, adds the original fix for
PR20208, and makes the error a warning in Microsoft mode.
llvm-svn: 235166
|
|
|
|
| |
llvm-svn: 229146
|
|
|
|
|
|
|
|
|
| |
We have a diagnostic describing that constexpr changed in C++14 when
compiling in C++11 mode. While doing this, it examines the previous
declaration and assumes that it is a function. However it is possible,
in the context of error recovery, for this to not be the case.
llvm-svn: 225518
|
|
|
|
|
|
| |
unevaluated expression context, such as sizeof(), or decltype(). Also adds a similar warning when the expression passed to typeid() *is* evaluated, since it is equally likely that the user would expect the expression operand to be unevaluated in that case.
llvm-svn: 224465
|
|
|
|
|
|
| |
temporaries.
llvm-svn: 224449
|
|
|
|
|
|
|
| |
Restricting this "extension" to array types maximizes our standards
conformance while not miscompiling real-world programs.
llvm-svn: 224215
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
clang lets programmers be pretty cavalier when it comes to void return
statements in functions which have non-void return types. However, we
cannot be so forgiving in constexpr functions: evaluation will go off
the rails very quickly.
Instead, keep the return statement in the AST but mark the function as
invalid. Doing so gives us nice diagnostics while making constexpr
evaluation halt.
This fixes PR21859.
llvm-svn: 224189
|
|
|
|
|
|
|
|
| |
Comparing the address of an object with an incomplete type might return
true with a 'distinct' object if the former has a size of zero.
However, such an object should compare unequal with null.
llvm-svn: 224040
|
|
|
|
|
|
|
|
| |
Zero sized objects may overlap with each other or any other object.
This fixes PR21786.
llvm-svn: 223852
|
|
|
|
|
|
|
| |
empty non-constexpr object. Such a copy doesn't break any of the constexpr
rules.
llvm-svn: 222387
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Specifically, when we have this situation:
struct A {
template <typename T> struct B {
int m1 = sizeof(A);
};
B<int> m2;
};
We can't parse m1's initializer eagerly because we need A to be
complete. Therefore we wait until the end of A's class scope to parse
it. However, we can trigger instantiation of B before the end of A,
which will attempt to instantiate the field decls eagerly, and it would
build a bad field decl instantiation that said it had an initializer but
actually lacked one.
Fixed by deferring instantiation of default member initializers until
they are needed during constructor analysis. This addresses a long
standing FIXME in the code.
Fixes PR19195.
Reviewed By: rsmith
Differential Revision: http://reviews.llvm.org/D5690
llvm-svn: 222192
|
|
|
|
|
|
| |
constant expressions.
llvm-svn: 221942
|
|
|
|
|
|
|
|
| |
complete object to a pointer to the start of another complete object does
not evaluate to the constant 'false'. All other comparisons between the
addresses of subobjects of distinct complete objects still do.
llvm-svn: 220343
|
|
|
|
|
|
|
| |
lists. Since the fields are inititalized one at a time, using a field with
lower index to initialize a higher indexed field should not be warned on.
llvm-svn: 218339
|
|
|
|
|
|
|
|
|
| |
constexpr function. Part of this fix is a tentative fix for an as-yet-unfiled
core issue (we're missing a prohibition against reading mutable members from
unions via a trivial constructor/assignment, since that doesn't perform an
lvalue-to-rvalue conversion on the members).
llvm-svn: 217852
|
|
|
|
|
|
| |
Changes diagnostic options, language standard options, diagnostic identifiers, diagnostic wording to use c++14 instead of c++1y. It also modifies related test cases to use the updated diagnostic wording.
llvm-svn: 215982
|
|
|
|
|
|
|
|
| |
This tweaks the diagnostic wording slighly, and adds a fixit on a note.
An alternative would be to add the fixit directly on the diagnostic, see
the review thread linked to from the bug for a few notes on that approach.
llvm-svn: 213725
|
|
|
|
|
|
| |
expression because it uses 'this'. Inspired by PR20219 comment#2.
llvm-svn: 212433
|
|
|
|
|
|
| |
non-literal class type.
llvm-svn: 210696
|
|
|
|
|
|
| |
evaluating trivial default initialization of a literal class type.
llvm-svn: 203025
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
| |
where we didn't. Extend our constant evaluation for __builtin_strlen to handle
any constant array of chars, not just string literals, to match.
llvm-svn: 194762
|
|
|
|
|
|
|
| |
to avoid breaking AST invariants by reusing Stmt nodes within the same
function.
llvm-svn: 194217
|
|
|
|
|
|
|
|
|
| |
bit more robust against future changes. This includes a slight diagnostic
improvement: if we know we're only trying to form a constant expression, take
the first diagnostic which shows the expression is not a constant expression,
rather than preferring the first one which makes the expression unfoldable.
llvm-svn: 194098
|
|
|
|
|
|
| |
we try to constant-evaluate it. Patch by Karthik Bhat, test by me.
llvm-svn: 190722
|
|
|
|
|
|
|
| |
treat such subtractions as being non-constant. Patch by Serge Pavlov! With a
few tweaks by me.
llvm-svn: 190439
|
|
|
|
|
|
| |
expression, truncate the stored value to the size of the bitfield.
llvm-svn: 187782
|
|
|
|
|
|
|
| |
objects to be used once their lifetimes end. This completes the C++1y
constexpr extensions.
llvm-svn: 187025
|
|
|
|
|
|
|
|
| |
Previously, for a field with an invalid in-class initializer, we
would create a CXXDefaultInitExpr referring to a null Expr*.
This is not a good idea.
llvm-svn: 185216
|
|
|
|
|
|
| |
when checking for overloads in C++1y.
llvm-svn: 184865
|
|
|
|
|
|
| |
why not. Apparently GCC supports this.
llvm-svn: 184396
|
|
|
|
|
|
|
| |
only permitted if the source object is of class type, and should materialize a
temporary for the reference to bind to.
llvm-svn: 184017
|
|
|
|
|
|
| |
type std::nullptr_t are null pointer constants from C++11 onwards.
llvm-svn: 183883
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Introduce CXXStdInitializerListExpr node, representing the implicit
construction of a std::initializer_list<T> object from its underlying array.
The AST representation of such an expression goes from an InitListExpr with a
flag set, to a CXXStdInitializerListExpr containing a MaterializeTemporaryExpr
containing an InitListExpr (possibly wrapped in a CXXBindTemporaryExpr).
This more detailed representation has several advantages, the most important of
which is that the new MaterializeTemporaryExpr allows us to directly model
lifetime extension of the underlying temporary array. Using that, this patch
*drastically* simplifies the IR generation of this construct, provides IR
generation support for nested global initializer_list objects, fixes several
bugs where the destructors for the underlying array would accidentally not get
invoked, and provides constant expression evaluation support for
std::initializer_list objects.
llvm-svn: 183872
|
|
|
|
|
|
| |
created through binding a reference-to-array to an initializer list.
llvm-svn: 183594
|
|
|
|
|
|
|
|
| |
must be initialized by a constant expression (not just a core constant
expression), because we're going to emit it as a global. Core issue for this is
pending.
llvm-svn: 183388
|
|
|
|
|
|
|
|
|
| |
handle temporaries which have been lifetime-extended to static storage duration
within constant expressions. This correctly handles nested lifetime extension
(through reference members of aggregates in aggregate initializers) but
non-constant-expression emission hasn't yet been updated to do the same.
llvm-svn: 183283
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
materialized temporary with the corresponding MaterializeTemporaryExpr. This is
groundwork for providing C++11's guaranteed static initialization for global
references bound to lifetime-extended temporaries (if the initialization is a
constant expression).
In passing, fix a couple of bugs where some evaluation failures didn't trigger
diagnostics, and a rejects-valid where potential constant expression testing
would assume that it knew the dynamic type of *this and would reject programs
which relied on it being some derived type.
llvm-svn: 183093
|
|
|
|
|
|
|
|
|
| |
* Treat _Atomic(T) as a literal type if T is a literal type.
* Evaluate expressions of this type properly.
* Fix a lurking bug where we built completely bogus ASTs for converting to
_Atomic types in C++ in some cases, caught by the tests for this change.
llvm-svn: 182541
|
|
|
|
|
|
| |
was erroneous and got discarded.
llvm-svn: 181758
|
|
|
|
| |
llvm-svn: 181159
|
|
|
|
|
|
|
|
| |
temporary to an lvalue before taking its address. This removes a weird special
case from the AST representation, and allows the constant expression evaluator
to deal with it without (broken) hacks.
llvm-svn: 180866
|
|
|
|
| |
llvm-svn: 180603
|
|
|
|
|
|
|
|
| |
statement in constexpr functions. Everything which doesn't require variable
mutation is also allowed as an extension in C++11. 'void' becomes a literal
type to support constexpr functions which return 'void'.
llvm-svn: 180022
|
|
|
|
|
|
|
| |
different array elements, even if they're all constructed using the same
default constructor.
llvm-svn: 180017
|
|
|
|
|
|
|
|
|
| |
C++1y, so stop adding the 'const' there. Provide a compatibility warning for
code relying on this in C++11, with a fix-it hint. Update our lazily-written
tests to add the const, except for those ones which were testing our
implementation of this rule.
llvm-svn: 179969
|