]> granicus.if.org Git - clang/commitdiff
Fix subtle bug introduced in r54852.
authorDaniel Dunbar <daniel@zuster.org>
Wed, 20 Aug 2008 03:55:42 +0000 (03:55 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 20 Aug 2008 03:55:42 +0000 (03:55 +0000)
 - UsualUnaryConversions takes an Expr *& and may modify its argument,
   this broke when it was refactored into Sema::CheckCastTypes. This
   meant that we were missing implicit casts in some places.
 - Seems pretty sad that this got through our tests.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55039 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaExpr.cpp
test/CodeGen/2008-08-19-cast-of-typedef.c [new file with mode: 0644]

index ed0108589743f011b4d4da64464ab18d1cd2db62..4bb54824fe232f34d9cc411cf1ade8c850fc242c 100644 (file)
@@ -871,7 +871,7 @@ private:
   bool CheckStringLiteralInit(StringLiteral *strLiteral, QualType &DeclT);
 
   /// CheckCastTypes - Check type constraints for casting between types.
-  bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *CastExpr);
+  bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr);
   
   // CheckVectorCast - check type constraints for vectors. 
   // Since vectors are an extension, there are no C standard reference for this.
index cac103a0447a1e4105dd8f97f9496ab256697f13..4781ffb57823a38bb8af6b9ae450e1be0cfb294a 100644 (file)
@@ -1089,7 +1089,7 @@ ActOnInitList(SourceLocation LBraceLoc, ExprTy **initlist, unsigned NumInit,
 }
 
 /// CheckCastTypes - Check type constraints for casting between types.
-bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *castExpr) {
+bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr) {
   UsualUnaryConversions(castExpr);
 
   // C99 6.5.4p2: the cast type needs to be void or scalar and the expression
diff --git a/test/CodeGen/2008-08-19-cast-of-typedef.c b/test/CodeGen/2008-08-19-cast-of-typedef.c
new file mode 100644 (file)
index 0000000..581c793
--- /dev/null
@@ -0,0 +1,10 @@
+// RUN: clang --emit-llvm -o %t %s
+
+typedef short T[4];
+struct s {
+  T f0;
+};
+
+void foo(struct s *x) {
+  bar((long) x->f0);
+}