Skip to content

Commit 4217ff2

Browse files
committed
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
1 parent 2b29125 commit 4217ff2

File tree

10 files changed

+67
-22
lines changed

10 files changed

+67
-22
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,8 +1008,11 @@ bool IntExprEvaluator::CheckReferencedDecl(const Expr* E, const Decl* D) {
10081008

10091009
VD->setEvaluatingValue();
10101010

1011-
if (Visit(const_cast<Expr*>(Init))) {
1011+
Expr::EvalResult EResult;
1012+
if (Init->Evaluate(EResult, Info.Ctx) && !EResult.HasSideEffects &&
1013+
EResult.Val.isInt()) {
10121014
// Cache the evaluated value in the variable declaration.
1015+
Result = EResult.Val;
10131016
VD->setEvaluatedValue(Result);
10141017
return true;
10151018
}

clang/lib/CodeGen/CGExprAgg.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,17 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) {
582582
// the optimizer, especially with bitfields.
583583
unsigned NumInitElements = E->getNumInits();
584584
RecordDecl *SD = E->getType()->getAs<RecordType>()->getDecl();
585-
unsigned CurInitVal = 0;
586-
585+
586+
// If we're initializing the whole aggregate, just do it in place.
587+
// FIXME: This is a hack around an AST bug (PR6537).
588+
if (NumInitElements == 1 && E->getType() == E->getInit(0)->getType()) {
589+
EmitInitializationToLValue(E->getInit(0),
590+
CGF.MakeAddrLValue(DestPtr, E->getType()),
591+
E->getType());
592+
return;
593+
}
594+
595+
587596
if (E->getType()->isUnionType()) {
588597
// Only initialize one field of a union. The field itself is
589598
// specified by the initializer list.
@@ -615,19 +624,10 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) {
615624

616625
return;
617626
}
618-
619-
// If we're initializing the whole aggregate, just do it in place.
620-
// FIXME: This is a hack around an AST bug (PR6537).
621-
if (NumInitElements == 1 && E->getType() == E->getInit(0)->getType()) {
622-
EmitInitializationToLValue(E->getInit(0),
623-
CGF.MakeAddrLValue(DestPtr, E->getType()),
624-
E->getType());
625-
return;
626-
}
627-
628627

629628
// Here we iterate over the fields; this makes it simpler to both
630629
// default-initialize fields and skip over unnamed fields.
630+
unsigned CurInitVal = 0;
631631
for (RecordDecl::field_iterator Field = SD->field_begin(),
632632
FieldEnd = SD->field_end();
633633
Field != FieldEnd; ++Field) {

clang/lib/Headers/stddef.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ typedef __typeof__(sizeof(int)) size_t;
3434
#ifndef __cplusplus
3535
#ifndef _WCHAR_T
3636
#define _WCHAR_T
37-
typedef __typeof__(*L"") wchar_t;
37+
typedef __WCHAR_TYPE__ wchar_t;
3838
#endif
3939
#endif
4040

clang/lib/Lex/Pragma.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,9 @@ void Preprocessor::HandlePragmaDependency(Token &DependencyTok) {
384384
Lex(DependencyTok);
385385
}
386386

387-
Message.erase(Message.end()-1);
387+
// Remove the trailing ' ' if present.
388+
if (!Message.empty())
389+
Message.erase(Message.end()-1);
388390
Diag(FilenameTok, diag::pp_out_of_date_dependency) << Message;
389391
}
390392
}

clang/lib/Sema/SemaExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6796,7 +6796,7 @@ ExprResult Sema::BuildUnaryOp(Scope *S, SourceLocation OpLoc,
67966796
UnaryOperatorKind Opc,
67976797
Expr *Input) {
67986798
if (getLangOptions().CPlusPlus && Input->getType()->isOverloadableType() &&
6799-
Opc != UO_Extension) {
6799+
UnaryOperator::getOverloadedOperator(Opc) != OO_None) {
68006800
// Find all of the overloaded operators visible from this
68016801
// point. We perform both an operator-name lookup from the local
68026802
// scope and an argument-dependent lookup based on the types of

clang/test/CodeGen/designated-initializers.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ struct foo {
88
// CHECK: @u = global %union.anon zeroinitializer
99
union { int i; float f; } u = { };
1010

11-
// CHECK: @u2 = global %0 { i32 0, [4 x i8] undef }
11+
// CHECK: @u2 = global %1 { i32 0, [4 x i8] undef }
1212
union { int i; double f; } u2 = { };
1313

14-
// CHECK: @u3 = global %1 zeroinitializer
14+
// CHECK: @u3 = global %2 zeroinitializer
1515
union { double f; int i; } u3 = { };
1616

1717
// CHECK: @b = global [2 x i32] [i32 0, i32 22]
1818
int b[2] = {
1919
[1] = 22
2020
};
2121

22-
int main(int argc, char **argv)
22+
void test1(int argc, char **argv)
2323
{
2424
// CHECK: internal global %struct.foo { i8* null, i32 1024 }
2525
static struct foo foo = {
@@ -33,5 +33,24 @@ int main(int argc, char **argv)
3333
// CHECK-NOT: call void @llvm.memset
3434
union { int i; float f; } u3;
3535

36-
// CHECK: ret i32
36+
// CHECK: ret void
37+
}
38+
39+
40+
// PR7151
41+
struct S {
42+
int nkeys;
43+
int *keys;
44+
union {
45+
void *data;
46+
};
47+
};
48+
49+
void test2() {
50+
struct S *btkr;
51+
52+
*btkr = (struct S) {
53+
.keys = 0,
54+
{ .data = 0 },
55+
};
3756
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clang_cc1 -verify -emit-llvm-only
2+
3+
// PR7242: Check that this doesn't crash.
4+
int main(void)
5+
{
6+
int __negative = 1;
7+
const int __max = __negative && 0 ;
8+
__max / 0;
9+
}

clang/test/Sema/warn-write-strings.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
// RUN: %clang_cc1 -verify -fsyntax-only -Wwrite-strings %s
22

33
// PR4804
4-
char* x = "foo"; // expected-warning {{initializing 'char *' with an expression of type 'char const [4]' discards qualifiers}}
4+
char* x = "foo"; // expected-warning {{initializing 'char *' with an expression of type 'const char [4]' discards qualifiers}}
5+
6+
// PR7192
7+
#include <stddef.h>
8+
void test(wchar_t *dst) {
9+
dst[0] = 0; // Ok.
10+
}

clang/test/SemaCXX/i-c-e-cxx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void f() {
1616
}
1717

1818
int a() {
19-
const int t=t; // expected-note {{subexpression not valid}}
19+
const int t=t;
2020
switch(1) { // expected-warning {{no case matching constant switch condition '1'}}
2121
case t:; // expected-error {{not an integer constant expression}}
2222
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
3+
struct A {};
4+
int i = __real__ A(); // expected-error {{invalid type 'A' to __real operator}}
5+
int j = __imag__ A(); // expected-error {{invalid type 'A' to __imag operator}}
6+

0 commit comments

Comments
 (0)