]> granicus.if.org Git - clang/commitdiff
Support member reference on ?: of struct type.
authorDaniel Dunbar <daniel@zuster.org>
Tue, 24 Mar 2009 02:38:23 +0000 (02:38 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 24 Mar 2009 02:38:23 +0000 (02:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67603 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExpr.cpp
lib/CodeGen/CodeGenFunction.h
test/CodeGen/exprs.c
test/Coverage/c-language-features.inc

index 45cd6a70a5de0f54dc23190456812f746977815a..b52c81eb0bc854607bdbc4aee8dc7f00dbd44478 100644 (file)
@@ -179,6 +179,8 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) {
   case Expr::MemberExprClass: return EmitMemberExpr(cast<MemberExpr>(E));
   case Expr::CompoundLiteralExprClass:
     return EmitCompoundLiteralLValue(cast<CompoundLiteralExpr>(E));
+  case Expr::ConditionalOperatorClass:
+    return EmitConditionalOperator(cast<ConditionalOperator>(E));
   case Expr::ChooseExprClass:
     return EmitLValue(cast<ChooseExpr>(E)->getChosenSubExpr(getContext()));
   case Expr::ImplicitCastExprClass:
@@ -1009,6 +1011,24 @@ LValue CodeGenFunction::EmitCompoundLiteralLValue(const CompoundLiteralExpr* E){
   return Result;
 }
 
+LValue CodeGenFunction::EmitConditionalOperator(const ConditionalOperator* E) {
+  // We don't handle vectors yet.
+  if (E->getType()->isVectorType())
+    return EmitUnsupportedLValue(E, "conditional operator");
+
+  // ?: here should be an aggregate.
+  assert((hasAggregateLLVMType(E->getType()) && 
+          !E->getType()->isAnyComplexType()) &&
+         "Unexpected conditional operator!");
+
+  llvm::Value *Temp = CreateTempAlloca(ConvertType(E->getType()));
+  EmitAggExpr(E, Temp, false);
+
+  return LValue::MakeAddr(Temp, E->getType().getCVRQualifiers(),
+                          getContext().getObjCGCAttrKind(E->getType()));
+}
+
 /// EmitCastLValue - Casts are never lvalues.  If a cast is needed by the code
 /// generator in an lvalue context, then it must mean that we need the address
 /// of an aggregate in order to access one of its fields.  This can happen for
index 9771c83d84c15545d31aca7bdebccab4f46d033d..acac86d8c2bad24e060379f527eddb706a7d16da 100644 (file)
@@ -608,6 +608,7 @@ public:
   LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
   LValue EmitMemberExpr(const MemberExpr *E);
   LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
+  LValue EmitConditionalOperator(const ConditionalOperator *E);
   LValue EmitCastLValue(const CastExpr *E);
 
   llvm::Value *EmitIvarOffset(ObjCInterfaceDecl *Interface,
index 808db178ef82611d3aa19d59417dd132893158d9..0e74b8c77322224c00cd8040d6aac5cb8b260117 100644 (file)
@@ -88,3 +88,9 @@ _Complex float f4() {return ((union f4_y)(_Complex float)2.0).y;}
 struct f5_a { int a; } f5_a;
 union f5_z {int x; struct f5_a y;};
 struct f5_a f5() {return ((union f5_z)f5_a).y;}
+
+// ?: in "lvalue"
+struct s6 { int f0; };
+int f6(int a0, struct s6 a1, struct s6 a2) {
+  return (a0 ? a1 : a2).f0;
+}
index 6a475d6c2fd658f8a2a7d49f82aeedc01c500cc4..656e8fe0c625e4285fe147e934305968617f10c4 100644 (file)
@@ -128,16 +128,32 @@ void f4(int a0, int a1, int a2, va_list ap) {
   struct { char f0[10]; } *t28;
   int t29 = t28 - t28;
   char *t30 = &t28->f0[1];
+
+  struct s1 { int f0; };
+  struct s1 t31_a, t31_b;
+  int t31_cond;
+  int t31 = (t31_cond ? t31_a : t31_b).f0;
+
+  _Complex float t32_a, t32_b;
+  int t32_cond;
+  int t32 = __real (t32_cond ? t32_a : t32_b);
 }
 
 // Extended vectors
 
+typedef __attribute__((ext_vector_type(2))) float float2;
 typedef __attribute__((ext_vector_type(4))) float float4;
 
 void f5() {
   float4 t0 = (float4) { 0, 1, 2, 3 };
   float4 t1 = t0;
   t0.lo.even = t1.hi.x;
+
+  // irgen doesn't support this yet.
+#if 0
+  int t2_cond;
+  float2 t2 = (t2_cond ? t0 : t1).lo;
+#endif
 }
 
 void f6() {