diff options
author | Bill Wendling <isanbard@gmail.com> | 2010-09-06 09:13:40 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2010-09-06 09:13:40 +0000 |
commit | 4217ff2da5168c500f3dc1e696baad1d10edb9f9 (patch) | |
tree | e9f30294a86bbebb408948670066754c7d608e11 | |
parent | 2b291257ece238655ef7f85f2f6f11c8d9f3efef (diff) | |
download | llvm-4217ff2da5168c500f3dc1e696baad1d10edb9f9.zip llvm-4217ff2da5168c500f3dc1e696baad1d10edb9f9.tar.gz llvm-4217ff2da5168c500f3dc1e696baad1d10edb9f9.tar.bz2 |
Approved by Chris:
$ svn merge -c 113124 https://llvm.org/svn/llvm-project/cfe/trunk
--- Merging r113124 into '.':
A test/SemaCXX/unary-real-imag.cpp
U lib/Sema/SemaExpr.cpp
Log:
PR8023: Don't crash on invalid uses of __real__ on class types in C++.
$ svn merge -c 113125 https://llvm.org/svn/llvm-project/cfe/trunk
--- Merging r113125 into '.':
U lib/Lex/Pragma.cpp
Log:
fix 7320: we can't delete a trailing space if it doesn't exist.
$ svn merge -c 113127 https://llvm.org/svn/llvm-project/cfe/trunk
--- Merging r113127 into '.':
U test/Sema/warn-write-strings.c
U lib/Headers/stddef.h
Log:
fix PR7192 by defining wchar_t in a more conventional way. The
type of L"x" can change based on command line arguments.
$ svn merge -c 113128 https://llvm.org/svn/llvm-project/cfe/trunk
--- Merging r113128 into '.':
A test/CodeGen/fold-const-declref.c
U lib/AST/ExprConstant.cpp
Log:
PR7242: Make sure to use a different context for evaluating constant
initializers, so the result of the evaluation doesn't leak through
inconsistently. Also, don't evaluate references to variables with
initializers with side-effects.
$ svn merge -c 113130 https://llvm.org/svn/llvm-project/cfe/trunk
--- Merging r113130 into '.':
U test/CodeGen/designated-initializers.c
U lib/CodeGen/CGExprAgg.cpp
Log:
move the hackaround for PR6537 to catch unions as well,
fixing the ICE in PR7151
$ svn merge -c 113131 https://llvm.org/svn/llvm-project/cfe/trunk
--- Merging r113131 into '.':
U test/SemaCXX/i-c-e-cxx.cpp
Log:
Update test for r113128.
llvm-svn: 113151
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 5 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGExprAgg.cpp | 24 | ||||
-rw-r--r-- | clang/lib/Headers/stddef.h | 2 | ||||
-rw-r--r-- | clang/lib/Lex/Pragma.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 2 | ||||
-rw-r--r-- | clang/test/CodeGen/designated-initializers.c | 27 | ||||
-rw-r--r-- | clang/test/CodeGen/fold-const-declref.c | 9 | ||||
-rw-r--r-- | clang/test/Sema/warn-write-strings.c | 8 | ||||
-rw-r--r-- | clang/test/SemaCXX/i-c-e-cxx.cpp | 2 | ||||
-rw-r--r-- | clang/test/SemaCXX/unary-real-imag.cpp | 6 |
10 files changed, 67 insertions, 22 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 175fd85..7347f5a 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -1008,8 +1008,11 @@ bool IntExprEvaluator::CheckReferencedDecl(const Expr* E, const Decl* D) { VD->setEvaluatingValue(); - if (Visit(const_cast<Expr*>(Init))) { + Expr::EvalResult EResult; + if (Init->Evaluate(EResult, Info.Ctx) && !EResult.HasSideEffects && + EResult.Val.isInt()) { // Cache the evaluated value in the variable declaration. + Result = EResult.Val; VD->setEvaluatedValue(Result); return true; } diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 2d8e2b2..28c8b35 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -582,8 +582,17 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { // the optimizer, especially with bitfields. unsigned NumInitElements = E->getNumInits(); RecordDecl *SD = E->getType()->getAs<RecordType>()->getDecl(); - unsigned CurInitVal = 0; - + + // If we're initializing the whole aggregate, just do it in place. + // FIXME: This is a hack around an AST bug (PR6537). + if (NumInitElements == 1 && E->getType() == E->getInit(0)->getType()) { + EmitInitializationToLValue(E->getInit(0), + CGF.MakeAddrLValue(DestPtr, E->getType()), + E->getType()); + return; + } + + if (E->getType()->isUnionType()) { // Only initialize one field of a union. The field itself is // specified by the initializer list. @@ -615,19 +624,10 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { return; } - - // If we're initializing the whole aggregate, just do it in place. - // FIXME: This is a hack around an AST bug (PR6537). - if (NumInitElements == 1 && E->getType() == E->getInit(0)->getType()) { - EmitInitializationToLValue(E->getInit(0), - CGF.MakeAddrLValue(DestPtr, E->getType()), - E->getType()); - return; - } - // Here we iterate over the fields; this makes it simpler to both // default-initialize fields and skip over unnamed fields. + unsigned CurInitVal = 0; for (RecordDecl::field_iterator Field = SD->field_begin(), FieldEnd = SD->field_end(); Field != FieldEnd; ++Field) { diff --git a/clang/lib/Headers/stddef.h b/clang/lib/Headers/stddef.h index fdd4815..84ec1a7 100644 --- a/clang/lib/Headers/stddef.h +++ b/clang/lib/Headers/stddef.h @@ -34,7 +34,7 @@ typedef __typeof__(sizeof(int)) size_t; #ifndef __cplusplus #ifndef _WCHAR_T #define _WCHAR_T -typedef __typeof__(*L"") wchar_t; +typedef __WCHAR_TYPE__ wchar_t; #endif #endif diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index 7975da5..a7b289e 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -384,7 +384,9 @@ void Preprocessor::HandlePragmaDependency(Token &DependencyTok) { Lex(DependencyTok); } - Message.erase(Message.end()-1); + // Remove the trailing ' ' if present. + if (!Message.empty()) + Message.erase(Message.end()-1); Diag(FilenameTok, diag::pp_out_of_date_dependency) << Message; } } diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 815a962..80b4652 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -6796,7 +6796,7 @@ ExprResult Sema::BuildUnaryOp(Scope *S, SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *Input) { if (getLangOptions().CPlusPlus && Input->getType()->isOverloadableType() && - Opc != UO_Extension) { + UnaryOperator::getOverloadedOperator(Opc) != OO_None) { // Find all of the overloaded operators visible from this // point. We perform both an operator-name lookup from the local // scope and an argument-dependent lookup based on the types of diff --git a/clang/test/CodeGen/designated-initializers.c b/clang/test/CodeGen/designated-initializers.c index 49f57ad..312d785 100644 --- a/clang/test/CodeGen/designated-initializers.c +++ b/clang/test/CodeGen/designated-initializers.c @@ -8,10 +8,10 @@ struct foo { // CHECK: @u = global %union.anon zeroinitializer union { int i; float f; } u = { }; -// CHECK: @u2 = global %0 { i32 0, [4 x i8] undef } +// CHECK: @u2 = global %1 { i32 0, [4 x i8] undef } union { int i; double f; } u2 = { }; -// CHECK: @u3 = global %1 zeroinitializer +// CHECK: @u3 = global %2 zeroinitializer union { double f; int i; } u3 = { }; // CHECK: @b = global [2 x i32] [i32 0, i32 22] @@ -19,7 +19,7 @@ int b[2] = { [1] = 22 }; -int main(int argc, char **argv) +void test1(int argc, char **argv) { // CHECK: internal global %struct.foo { i8* null, i32 1024 } static struct foo foo = { @@ -33,5 +33,24 @@ int main(int argc, char **argv) // CHECK-NOT: call void @llvm.memset union { int i; float f; } u3; - // CHECK: ret i32 + // CHECK: ret void +} + + +// PR7151 +struct S { + int nkeys; + int *keys; + union { + void *data; + }; +}; + +void test2() { + struct S *btkr; + + *btkr = (struct S) { + .keys = 0, + { .data = 0 }, + }; } diff --git a/clang/test/CodeGen/fold-const-declref.c b/clang/test/CodeGen/fold-const-declref.c new file mode 100644 index 0000000..5a7ba8e --- /dev/null +++ b/clang/test/CodeGen/fold-const-declref.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -verify -emit-llvm-only + +// PR7242: Check that this doesn't crash. +int main(void) +{ + int __negative = 1; + const int __max = __negative && 0 ; + __max / 0; +} diff --git a/clang/test/Sema/warn-write-strings.c b/clang/test/Sema/warn-write-strings.c index 04af00c..dd0bb8a 100644 --- a/clang/test/Sema/warn-write-strings.c +++ b/clang/test/Sema/warn-write-strings.c @@ -1,4 +1,10 @@ // RUN: %clang_cc1 -verify -fsyntax-only -Wwrite-strings %s // PR4804 -char* x = "foo"; // expected-warning {{initializing 'char *' with an expression of type 'char const [4]' discards qualifiers}} +char* x = "foo"; // expected-warning {{initializing 'char *' with an expression of type 'const char [4]' discards qualifiers}} + +// PR7192 +#include <stddef.h> +void test(wchar_t *dst) { + dst[0] = 0; // Ok. +} diff --git a/clang/test/SemaCXX/i-c-e-cxx.cpp b/clang/test/SemaCXX/i-c-e-cxx.cpp index 9672a42..2d08ea9 100644 --- a/clang/test/SemaCXX/i-c-e-cxx.cpp +++ b/clang/test/SemaCXX/i-c-e-cxx.cpp @@ -16,7 +16,7 @@ void f() { } int a() { - const int t=t; // expected-note {{subexpression not valid}} + const int t=t; switch(1) { // expected-warning {{no case matching constant switch condition '1'}} case t:; // expected-error {{not an integer constant expression}} } diff --git a/clang/test/SemaCXX/unary-real-imag.cpp b/clang/test/SemaCXX/unary-real-imag.cpp new file mode 100644 index 0000000..91b63e3 --- /dev/null +++ b/clang/test/SemaCXX/unary-real-imag.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +struct A {}; +int i = __real__ A(); // expected-error {{invalid type 'A' to __real operator}} +int j = __imag__ A(); // expected-error {{invalid type 'A' to __imag operator}} + |