]> granicus.if.org Git - clang/commitdiff
Silly special case: never load when dereferencing void*.
authorJohn McCall <rjmccall@apple.com>
Sat, 4 Dec 2010 12:43:24 +0000 (12:43 +0000)
committerJohn McCall <rjmccall@apple.com>
Sat, 4 Dec 2010 12:43:24 +0000 (12:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120905 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprScalar.cpp
test/CodeGen/exprs.c

index 8ed8cb38db2713ac335109a206d7d435b36e166a..a65eae8f78ae44fdfa13f70a4387b11dfb215175 100644 (file)
@@ -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();
index 452c823d15fb04466e3ff36aa6daef6237027a2f..b03539333cd78781ae27212c7794a8c97fe38955 100644 (file)
@@ -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
 }