]> granicus.if.org Git - clang/commitdiff
Fix codegen for conditionals with incommpatible pointer types. Code
authorEli Friedman <eli.friedman@gmail.com>
Wed, 30 Jan 2008 17:02:03 +0000 (17:02 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 30 Jan 2008 17:02:03 +0000 (17:02 +0000)
that causes this isn't really correct, but if we're going to accept
this, it should come up with a consistent AST.

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

Sema/SemaExpr.cpp
test/CodeGen/conditional.c

index a1cdb225662aaa4864b16fc0b25b0696b0e499a0..bb4cb519f0be661bbd5f65dde371ffa02913bfbc 100644 (file)
@@ -823,7 +823,13 @@ inline QualType Sema::CheckConditionalOperands( // C99 6.5.15
         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
index 15359e0c8ac183e809a809d2f513ae992d8b1fdc..24a5aca57781a937ca3d409b93071cd60b19de65 100644 (file)
@@ -15,3 +15,7 @@ void test3(){
    1 ? f() : (void)0;
 }
 
+void test4() {
+int i; short j;
+float* k = 1 ? &i : &j;
+}