From 1bc0fed9a52d867b5b4be45283dc1b83a81f4f28 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Wed, 30 Jan 2008 17:02:03 +0000 Subject: [PATCH] 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. llvm-svn: 46557 --- clang/Sema/SemaExpr.cpp | 8 +++++++- clang/test/CodeGen/conditional.c | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/clang/Sema/SemaExpr.cpp b/clang/Sema/SemaExpr.cpp index a1cdb225662a..bb4cb519f0be 100644 --- a/clang/Sema/SemaExpr.cpp +++ b/clang/Sema/SemaExpr.cpp @@ -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 diff --git a/clang/test/CodeGen/conditional.c b/clang/test/CodeGen/conditional.c index 15359e0c8ac1..24a5aca57781 100644 --- a/clang/test/CodeGen/conditional.c +++ b/clang/test/CodeGen/conditional.c @@ -15,3 +15,7 @@ void test3(){ 1 ? f() : (void)0; } +void test4() { +int i; short j; +float* k = 1 ? &i : &j; +}