]> granicus.if.org Git - clang/commitdiff
Fix bitfield promotions in several more cases. We don't seem to work hard enough...
authorDouglas Gregor <dgregor@apple.com>
Sat, 2 May 2009 00:36:19 +0000 (00:36 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 2 May 2009 00:36:19 +0000 (00:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70613 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/bitfield.c

index 3442cc1db9f8ccb1a0e8f5a629c2554f623e27a8..47b9fbd7bce9d132d5cd775fca6ca92cdf594b79 100644 (file)
@@ -264,6 +264,14 @@ QualType Sema::UsualArithmeticConversions(Expr *&lhsExpr, Expr *&rhsExpr,
   if (!lhs->isArithmeticType() || !rhs->isArithmeticType())
     return lhs;
 
+  // Perform bitfield promotions.
+  QualType LHSBitfieldPromoteTy = isPromotableBitField(lhsExpr, Context);
+  if (!LHSBitfieldPromoteTy.isNull())
+    lhs = LHSBitfieldPromoteTy;
+  QualType RHSBitfieldPromoteTy = isPromotableBitField(rhsExpr, Context);
+  if (!RHSBitfieldPromoteTy.isNull())
+    rhs = RHSBitfieldPromoteTy;
+
   QualType destType = UsualArithmeticConversionsType(lhs, rhs);
   if (!isCompAssign)
     ImpCastExprToType(lhsExpr, destType);
@@ -3475,6 +3483,12 @@ inline QualType Sema::CheckAdditionOperands( // C99 6.5.6
         QualType LHSTy = lex->getType();
         if (LHSTy->isPromotableIntegerType())
           LHSTy = Context.IntTy;
+        else {
+          QualType T = isPromotableBitField(lex, Context);
+          if (!T.isNull())
+            LHSTy = T;
+        }
+
         *CompLHSTy = LHSTy;
       }
       return PExp->getType();
@@ -3628,8 +3642,11 @@ QualType Sema::CheckShiftOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
   QualType LHSTy;
   if (lex->getType()->isPromotableIntegerType())
     LHSTy = Context.IntTy;
-  else
-    LHSTy = lex->getType();
+  else {
+    LHSTy = isPromotableBitField(lex, Context);
+    if (LHSTy.isNull())
+      LHSTy = lex->getType();
+  }
   if (!isCompAssign)
     ImpCastExprToType(lex, LHSTy);
 
@@ -4067,7 +4084,7 @@ QualType Sema::CheckAssignmentOperands(Expr *LHS, Expr *&RHS,
   // C99 6.5.16.1p2: In simple assignment, the value of the right operand
   // is converted to the type of the assignment expression (above).
   // C++ 5.17p1: the type of the assignment expression is that of its left
-  // oprdu.
+  // operand.
   return LHSType.getUnqualifiedType();
 }
 
index e81b802789a96ba2a986e8db9f62c0d20d1b0ebc..526a225ff2c8bf4231c94997d36b11fdf99b8277 100644 (file)
@@ -29,3 +29,8 @@ struct a {
 struct b {unsigned x : 2;} x;
 __typeof__(x.x+1) y;
 int y;
+
+struct {unsigned x : 2;} x2;
+// FIXME: __typeof__((x.x+=1)+1) y;
+__typeof__(x.x<<1) y;
+int y;