[cfe-commits] r92064 - in /cfe/trunk: lib/CodeGen/CGException.cpp lib/CodeGen/CGExprCXX.cpp lib/CodeGen/Mangle.cpp lib/Sema/SemaExprCXX.cpp test/CodeGenCXX/try-catch.cpp
Douglas Gregor
dgregor at apple.com
Wed Dec 23 14:04:40 PST 2009
Author: dgregor
Date: Wed Dec 23 16:04:40 2009
New Revision: 92064
URL: http://llvm.org/viewvc/llvm-project?rev=92064&view=rev
Log:
There is no such thing as typeinfo for a cv-qualified type. Assert
that this is true when mangling, then fix up the various places in
Sema and/or CodeGen that need to remove qualifiers. Addresses a
linking issue when building LLVM with Clang.
Added:
cfe/trunk/test/CodeGenCXX/try-catch.cpp
Modified:
cfe/trunk/lib/CodeGen/CGException.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/CodeGen/Mangle.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
Modified: cfe/trunk/lib/CodeGen/CGException.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=92064&r1=92063&r2=92064&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGException.cpp Wed Dec 23 16:04:40 2009
@@ -367,7 +367,9 @@
for (unsigned i = 0; i < Proto->getNumExceptions(); ++i) {
QualType Ty = Proto->getExceptionType(i);
- llvm::Value *EHType = CGM.GetAddrOfRTTIDescriptor(Ty.getNonReferenceType());
+ QualType ExceptType
+ = Ty.getNonReferenceType().getUnqualifiedType();
+ llvm::Value *EHType = CGM.GetAddrOfRTTIDescriptor(ExceptType);
SelectorArgs.push_back(EHType);
}
if (Proto->getNumExceptions())
@@ -506,8 +508,11 @@
const CXXCatchStmt *C = S.getHandler(i);
VarDecl *CatchParam = C->getExceptionDecl();
if (CatchParam) {
+ // C++ [except.handle]p3 indicates that top-level cv-qualifiers
+ // are ignored.
+ QualType CaughtType = C->getCaughtType().getNonReferenceType();
llvm::Value *EHTypeInfo
- = CGM.GetAddrOfRTTIDescriptor(C->getCaughtType().getNonReferenceType());
+ = CGM.GetAddrOfRTTIDescriptor(CaughtType.getUnqualifiedType());
SelectorArgs.push_back(EHTypeInfo);
} else {
// null indicates catch all
Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=92064&r1=92063&r2=92064&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Wed Dec 23 16:04:40 2009
@@ -548,8 +548,10 @@
assert(SrcTy->isRecordType() && "Src type must be record type!");
assert(DestTy->isRecordType() && "Dest type must be record type!");
- llvm::Value *SrcArg = CGM.GetAddrOfRTTIDescriptor(SrcTy);
- llvm::Value *DestArg = CGM.GetAddrOfRTTIDescriptor(DestTy);
+ llvm::Value *SrcArg
+ = CGM.GetAddrOfRTTIDescriptor(SrcTy.getUnqualifiedType());
+ llvm::Value *DestArg
+ = CGM.GetAddrOfRTTIDescriptor(DestTy.getUnqualifiedType());
V = Builder.CreateBitCast(V, PtrToInt8Ty);
V = Builder.CreateCall4(CGM.CreateRuntimeFunction(FTy, "__dynamic_cast"),
Modified: cfe/trunk/lib/CodeGen/Mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.cpp?rev=92064&r1=92063&r2=92064&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Wed Dec 23 16:04:40 2009
@@ -1586,6 +1586,7 @@
void MangleContext::mangleCXXRTTI(QualType Ty,
llvm::SmallVectorImpl<char> &Res) {
// <special-name> ::= TI <type> # typeinfo structure
+ assert(!Ty.hasQualifiers() && "RTTI info cannot have top-level qualifiers");
CXXNameMangler Mangler(*this, Res);
Mangler.getStream() << "_ZTI";
Mangler.mangleType(Ty);
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=92064&r1=92063&r2=92064&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Dec 23 16:04:40 2009
@@ -137,8 +137,15 @@
/// CheckCXXThrowOperand - Validate the operand of a throw.
bool Sema::CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *&E) {
// C++ [except.throw]p3:
- // [...] adjusting the type from "array of T" or "function returning T"
- // to "pointer to T" or "pointer to function returning T", [...]
+ // A throw-expression initializes a temporary object, called the exception
+ // object, the type of which is determined by removing any top-level
+ // cv-qualifiers from the static type of the operand of throw and adjusting
+ // the type from "array of T" or "function returning T" to "pointer to T"
+ // or "pointer to function returning T", [...]
+ if (E->getType().hasQualifiers())
+ ImpCastExprToType(E, E->getType().getUnqualifiedType(), CastExpr::CK_NoOp,
+ E->isLvalue(Context) == Expr::LV_Valid);
+
DefaultFunctionArrayConversion(E);
// If the type of the exception would be an incomplete type or a pointer
Added: cfe/trunk/test/CodeGenCXX/try-catch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/try-catch.cpp?rev=92064&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/try-catch.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/try-catch.cpp Wed Dec 23 16:04:40 2009
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - -fexceptions | FileCheck %s
+
+struct X { };
+
+const X g();
+
+void f() {
+ try {
+ throw g();
+ // CHECK: @_ZTI1X to i8
+ } catch (const X x) {
+ }
+}
More information about the cfe-commits
mailing list