From 0b7bc7f99612e150304b83c5149b220b959b7341 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 29 Jan 2013 01:26:43 +0000 Subject: [PATCH] Don't crash while printing APValues that are lvalues casted to a decidedly non-reference, non-pointer type. Fixes . llvm-svn: 173747 --- clang/lib/AST/APValue.cpp | 2 ++ clang/test/CXX/expr/expr.const/p2-0x.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp index 1676b7d..98e825b 100644 --- a/clang/lib/AST/APValue.cpp +++ b/clang/lib/AST/APValue.cpp @@ -348,6 +348,8 @@ void APValue::printPretty(raw_ostream &Out, ASTContext &Ctx, QualType Ty) const{ bool IsReference = Ty->isReferenceType(); QualType InnerTy = IsReference ? Ty.getNonReferenceType() : Ty->getPointeeType(); + if (InnerTy.isNull()) + InnerTy = Ty; if (!hasLValuePath()) { // No lvalue path: just print the offset. diff --git a/clang/test/CXX/expr/expr.const/p2-0x.cpp b/clang/test/CXX/expr/expr.const/p2-0x.cpp index 9e6716d..065a12b3 100644 --- a/clang/test/CXX/expr/expr.const/p2-0x.cpp +++ b/clang/test/CXX/expr/expr.const/p2-0x.cpp @@ -594,3 +594,16 @@ static const bool or_value = and_or::or_value; static_assert(and_value == false, ""); static_assert(or_value == true, ""); + +namespace rdar13090123 { + typedef __INTPTR_TYPE__ intptr_t; + + constexpr intptr_t f(intptr_t x) { + return (((x) >> 21) * 8); // expected-note{{subexpression not valid in a constant expression}} + } + + extern "C" int foo; + + constexpr intptr_t i = f((intptr_t)&foo - 10); // expected-error{{constexpr variable 'i' must be initialized by a constant expression}} \ + // expected-note{{in call to 'f((char*)&foo + -10)'}} +} -- 2.7.4