From 627c0f59d20cf9c4e563e2dbec578f255e44bdb8 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Mon, 6 Sep 2010 09:13:40 +0000 Subject: 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_28@113151 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ExprConstant.cpp | 5 ++++- lib/CodeGen/CGExprAgg.cpp | 24 ++++++++++++------------ lib/Headers/stddef.h | 2 +- lib/Lex/Pragma.cpp | 4 +++- lib/Sema/SemaExpr.cpp | 2 +- test/CodeGen/designated-initializers.c | 27 +++++++++++++++++++++++---- test/CodeGen/fold-const-declref.c | 9 +++++++++ test/Sema/warn-write-strings.c | 8 +++++++- test/SemaCXX/i-c-e-cxx.cpp | 2 +- test/SemaCXX/unary-real-imag.cpp | 6 ++++++ 10 files changed, 67 insertions(+), 22 deletions(-) create mode 100644 test/CodeGen/fold-const-declref.c create mode 100644 test/SemaCXX/unary-real-imag.cpp diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 175fd85a24..7347f5a43e 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -1008,8 +1008,11 @@ bool IntExprEvaluator::CheckReferencedDecl(const Expr* E, const Decl* D) { VD->setEvaluatingValue(); - if (Visit(const_cast(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/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index 2d8e2b2b42..28c8b3545b 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/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()->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/lib/Headers/stddef.h b/lib/Headers/stddef.h index fdd48159ba..84ec1a7b4e 100644 --- a/lib/Headers/stddef.h +++ b/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/lib/Lex/Pragma.cpp b/lib/Lex/Pragma.cpp index 7975da58b6..a7b289e137 100644 --- a/lib/Lex/Pragma.cpp +++ b/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/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 815a962262..80b465230e 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/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/test/CodeGen/designated-initializers.c b/test/CodeGen/designated-initializers.c index 49f57ad062..312d785652 100644 --- a/test/CodeGen/designated-initializers.c +++ b/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/test/CodeGen/fold-const-declref.c b/test/CodeGen/fold-const-declref.c new file mode 100644 index 0000000000..5a7ba8e26a --- /dev/null +++ b/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/test/Sema/warn-write-strings.c b/test/Sema/warn-write-strings.c index 04af00ca2d..dd0bb8a6d8 100644 --- a/test/Sema/warn-write-strings.c +++ b/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 +void test(wchar_t *dst) { + dst[0] = 0; // Ok. +} diff --git a/test/SemaCXX/i-c-e-cxx.cpp b/test/SemaCXX/i-c-e-cxx.cpp index 9672a420dc..2d08ea9a42 100644 --- a/test/SemaCXX/i-c-e-cxx.cpp +++ b/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/test/SemaCXX/unary-real-imag.cpp b/test/SemaCXX/unary-real-imag.cpp new file mode 100644 index 0000000000..91b63e37b9 --- /dev/null +++ b/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}} + -- cgit v1.2.3