[cfe-commits] r60924 - in /cfe/trunk: lib/AST/Expr.cpp lib/CodeGen/CGExpr.cpp test/Sema/exprs.c

Chris Lattner sabre at nondot.org
Thu Dec 11 21:35:08 PST 2008


Author: lattner
Date: Thu Dec 11 23:35:08 2008
New Revision: 60924

URL: http://llvm.org/viewvc/llvm-project?rev=60924&view=rev
Log:
Fix rdar://6095061 - gcc allows __builtin_choose_expr as an lvalue


Modified:
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/test/Sema/exprs.c

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=60924&r1=60923&r2=60924&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Thu Dec 11 23:35:08 2008
@@ -467,6 +467,13 @@
   }
   case CompoundLiteralExprClass: // C99 6.5.2.5p5
     return LV_Valid;
+  case ChooseExprClass:
+    // __builtin_choose_expr is an lvalue if the selected operand is.
+    if (cast<ChooseExpr>(this)->isConditionTrue(Ctx))
+      return cast<ChooseExpr>(this)->getLHS()->isLvalue(Ctx);
+    else
+      return cast<ChooseExpr>(this)->getRHS()->isLvalue(Ctx);
+
   case ExtVectorElementExprClass:
     if (cast<ExtVectorElementExpr>(this)->containsDuplicateElements())
       return LV_DuplicateVectorComponents;
@@ -476,7 +483,7 @@
   case ObjCPropertyRefExprClass: // FIXME: check if read-only property.
     return LV_Valid;
   case ObjCKVCRefExprClass: // FIXME: check if read-only property.
-      return LV_Valid;
+    return LV_Valid;
   case PredefinedExprClass:
     return LV_Valid;
   case VAArgExprClass:
@@ -1213,8 +1220,7 @@
   return getCond()->getIntegerConstantExprValue(C) != 0;
 }
 
-static int64_t evaluateOffsetOf(ASTContext& C, const Expr *E)
-{
+static int64_t evaluateOffsetOf(ASTContext& C, const Expr *E) {
   if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) {
     QualType Ty = ME->getBase()->getType();
     

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=60924&r1=60923&r2=60924&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Dec 11 23:35:08 2008
@@ -146,6 +146,12 @@
   case Expr::MemberExprClass: return EmitMemberExpr(cast<MemberExpr>(E));
   case Expr::CompoundLiteralExprClass:
     return EmitCompoundLiteralLValue(cast<CompoundLiteralExpr>(E));
+  case Expr::ChooseExprClass:
+    // __builtin_choose_expr is the lvalue of the selected operand.
+    if (cast<ChooseExpr>(E)->isConditionTrue(getContext()))
+      return EmitLValue(cast<ChooseExpr>(E)->getLHS());
+    else
+      return EmitLValue(cast<ChooseExpr>(E)->getRHS());
   }
 }
 

Modified: cfe/trunk/test/Sema/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/exprs.c?rev=60924&r1=60923&r2=60924&view=diff

==============================================================================
--- cfe/trunk/test/Sema/exprs.c (original)
+++ cfe/trunk/test/Sema/exprs.c Thu Dec 11 23:35:08 2008
@@ -38,3 +38,10 @@
    P = (P-42) + Gamma*4;  // expected-error {{invalid operands to binary expression ('int *' and '_Complex float')}}
 }
 
+
+// rdar://6095061
+int test8(void) {
+  int i;
+  __builtin_choose_expr (0, 42, i) = 10;
+  return i;
+}





More information about the cfe-commits mailing list