From: John McCall Date: Sat, 4 Dec 2010 12:43:24 +0000 (+0000) Subject: Silly special case: never load when dereferencing void*. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fd569004b78124c1041feee75a1e311166268c8d;p=clang Silly special case: never load when dereferencing void*. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120905 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 8ed8cb38db..a65eae8f78 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -312,7 +312,11 @@ public: // value as the "address". return EmitLValue(E->getSubExpr()).getAddress(); } - Value *VisitUnaryDeref(const Expr *E) { return EmitLoadOfLValue(E); } + Value *VisitUnaryDeref(const UnaryOperator *E) { + if (E->getType()->isVoidType()) + return Visit(E->getSubExpr()); // the actual value should be unused + return EmitLoadOfLValue(E); + } Value *VisitUnaryPlus(const UnaryOperator *E) { // This differs from gcc, though, most likely due to a bug in gcc. TestAndClearIgnoreResultAssign(); diff --git a/test/CodeGen/exprs.c b/test/CodeGen/exprs.c index 452c823d15..b03539333c 100644 --- a/test/CodeGen/exprs.c +++ b/test/CodeGen/exprs.c @@ -152,17 +152,17 @@ void f14(struct s14 *a) { } // CHECK: define void @f15 -void f15(void *v, const void *cv, volatile void *vv) { - extern void f15_helper(void); - f15_helper(); - // CHECK: call void @f15_helper() - // FIXME: no loads from i8* should occur here at all! - *v; *v, *v; v ? *v : *v; - *cv; *cv, *cv; v ? *cv : *cv; - *vv; *vv, *vv; vv ? *vv : *vv; - // CHECK: volatile load i8* - // CHECK: volatile load i8* - // CHECK: volatile load i8* - // CHECK-NOT: load i8* % +void f15() { + extern void f15_start(void); + f15_start(); + // CHECK: call void @f15_start() + + extern void *f15_v(void); + extern const void *f15_cv(void); + extern volatile void *f15_vv(void); + *f15_v(); *f15_v(), *f15_v(); f15_v() ? *f15_v() : *f15_v(); + *f15_cv(); *f15_cv(), *f15_cv(); f15_cv() ? *f15_cv() : *f15_cv(); + *f15_vv(); *f15_vv(), *f15_vv(); f15_vv() ? *f15_vv() : *f15_vv(); + // CHECK-NOT: load // CHECK: ret void }