[cfe-commits] r46557 - in /cfe/trunk: Sema/SemaExpr.cpp test/CodeGen/conditional.c

Eli Friedman eli.friedman at gmail.com
Wed Jan 30 09:02:03 PST 2008


Author: efriedma
Date: Wed Jan 30 11:02:03 2008
New Revision: 46557

URL: http://llvm.org/viewvc/llvm-project?rev=46557&view=rev
Log:
Fix codegen for conditionals with incommpatible pointer types.  Code 
that causes this isn't really correct, but if we're going to accept 
this, it should come up with a consistent AST.

Modified:
    cfe/trunk/Sema/SemaExpr.cpp
    cfe/trunk/test/CodeGen/conditional.c

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

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Wed Jan 30 11:02:03 2008
@@ -823,7 +823,13 @@
         Diag(questionLoc, diag::ext_typecheck_cond_incompatible_pointers,
              lexT.getAsString(), rexT.getAsString(),
              lex->getSourceRange(), rex->getSourceRange());
-        return lexT; // FIXME: this is an _ext - is this return o.k?
+        // In this situation, we assume void* type. No especially good
+        // reason, but this is what gcc does, and we do have to pick
+        // to get a consistent AST.
+        QualType voidPtrTy = Context.getPointerType(Context.VoidTy);
+        ImpCastExprToType(lex, voidPtrTy);
+        ImpCastExprToType(rex, voidPtrTy);
+        return voidPtrTy;
       }
       // The pointer types are compatible.
       // C99 6.5.15p6: If both operands are pointers to compatible types *or* to

Modified: cfe/trunk/test/CodeGen/conditional.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/conditional.c?rev=46557&r1=46556&r2=46557&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/conditional.c (original)
+++ cfe/trunk/test/CodeGen/conditional.c Wed Jan 30 11:02:03 2008
@@ -15,3 +15,7 @@
    1 ? f() : (void)0;
 }
 
+void test4() {
+int i; short j;
+float* k = 1 ? &i : &j;
+}





More information about the cfe-commits mailing list