[cfe-commits] r54068 - /cfe/trunk/lib/Sema/SemaExpr.cpp

Chris Lattner sabre at nondot.org
Fri Jul 25 15:06:11 PDT 2008


Author: lattner
Date: Fri Jul 25 17:06:10 2008
New Revision: 54068

URL: http://llvm.org/viewvc/llvm-project?rev=54068&view=rev
Log:
Fix a couple bugs in aggregate cast processing: 1) fix precedecence 
problem with &&/||.  2) use canonical types for comparison instead 
of raw types. 3) emit an ext-warn for a gnu extension.

Also simplify the code to make it less nested.


Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=54068&r1=54067&r2=54068&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Jul 25 17:06:10 2008
@@ -1122,33 +1122,34 @@
 
   // C99 6.5.4p2: the cast type needs to be void or scalar and the expression
   // type needs to be scalar.
-  if (!castType->isVoidType()) {  // Cast to void allows any expr type.
-    if (!castType->isScalarType() && !castType->isVectorType()) {
-      // GCC struct/union extension.
-      if (castType == castExpr->getType() &&
-          castType->isStructureType() || castType->isUnionType()) {
-        Diag(LParenLoc, diag::ext_typecheck_cast_nonscalar,
-             SourceRange(LParenLoc, RParenLoc));
-        return new CastExpr(castType, castExpr, LParenLoc);
-      } else
-        return Diag(LParenLoc, diag::err_typecheck_cond_expect_scalar, 
-                    castType.getAsString(), SourceRange(LParenLoc, RParenLoc));
-    }
-    if (!castExpr->getType()->isScalarType() && 
-        !castExpr->getType()->isVectorType())
-      return Diag(castExpr->getLocStart(), 
-                  diag::err_typecheck_expect_scalar_operand, 
-                  castExpr->getType().getAsString(),castExpr->getSourceRange());
-
-    if (castExpr->getType()->isVectorType()) {
-      if (CheckVectorCast(SourceRange(LParenLoc, RParenLoc), 
-                          castExpr->getType(), castType))
-        return true;
-    } else if (castType->isVectorType()) {
-      if (CheckVectorCast(SourceRange(LParenLoc, RParenLoc), 
-                          castType, castExpr->getType()))
-        return true;
+  if (castType->isVoidType()) {
+    // Cast to void allows any expr type.
+  } else if (!castType->isScalarType() && !castType->isVectorType()) {
+    // GCC struct/union extension: allow cast to self.
+    if (Context.getCanonicalType(castType) !=
+        Context.getCanonicalType(castExpr->getType()) ||
+        (!castType->isStructureType() && !castType->isUnionType())) {
+      // Reject any other conversions to non-scalar types.
+      return Diag(LParenLoc, diag::err_typecheck_cond_expect_scalar, 
+                  castType.getAsString(), castExpr->getSourceRange());
     }
+      
+    // accept this, but emit an ext-warn.
+    Diag(LParenLoc, diag::ext_typecheck_cast_nonscalar, 
+         castType.getAsString(), castExpr->getSourceRange());
+  } else if (!castExpr->getType()->isScalarType() && 
+             !castExpr->getType()->isVectorType()) {
+    return Diag(castExpr->getLocStart(), 
+                diag::err_typecheck_expect_scalar_operand, 
+                castExpr->getType().getAsString(),castExpr->getSourceRange());
+  } else if (castExpr->getType()->isVectorType()) {
+    if (CheckVectorCast(SourceRange(LParenLoc, RParenLoc), 
+                        castExpr->getType(), castType))
+      return true;
+  } else if (castType->isVectorType()) {
+    if (CheckVectorCast(SourceRange(LParenLoc, RParenLoc), 
+                        castType, castExpr->getType()))
+      return true;
   }
   return new CastExpr(castType, castExpr, LParenLoc);
 }





More information about the cfe-commits mailing list