summaryrefslogtreecommitdiffstats
path: root/lib/Sema/TypeLocBuilder.h
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2013-02-18 22:06:02 +0000
committerDavid Blaikie <dblaikie@gmail.com>2013-02-18 22:06:02 +0000
commit39e6ab4be93d9c5e729a578ddd9d415cd2d49872 (patch)
treefc9c9aad9c0b7b392ff2b08bb1d5df59c8d6c048 /lib/Sema/TypeLocBuilder.h
parent9ba7627d25a7555b1afff04f685d2f161974e682 (diff)
Replace TypeLoc llvm::cast support to be well-defined.
The TypeLoc hierarchy used the llvm::cast machinery to perform undefined behavior by casting pointers/references to TypeLoc objects to derived types and then using the derived copy constructors (or even returning pointers to derived types that actually point to the original TypeLoc object). Some context is in this thread: http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-December/056804.html Though it's spread over a few months which can be hard to read in the mail archive. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175462 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/TypeLocBuilder.h')
-rw-r--r--lib/Sema/TypeLocBuilder.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/Sema/TypeLocBuilder.h b/lib/Sema/TypeLocBuilder.h
index 3da316d2a3..f36ec9f3e2 100644
--- a/lib/Sema/TypeLocBuilder.h
+++ b/lib/Sema/TypeLocBuilder.h
@@ -75,7 +75,7 @@ class TypeLocBuilder {
/// previously retrieved from this builder.
TypeSpecTypeLoc pushTypeSpec(QualType T) {
size_t LocalSize = TypeSpecTypeLoc::LocalDataSize;
- return cast<TypeSpecTypeLoc>(pushImpl(T, LocalSize));
+ return pushImpl(T, LocalSize).castAs<TypeSpecTypeLoc>();
}
/// Resets this builder to the newly-initialized state.
@@ -97,8 +97,8 @@ class TypeLocBuilder {
/// Pushes space for a new TypeLoc of the given type. Invalidates
/// any TypeLocs previously retrieved from this builder.
template <class TyLocType> TyLocType push(QualType T) {
- size_t LocalSize = cast<TyLocType>(TypeLoc(T, 0)).getLocalDataSize();
- return cast<TyLocType>(pushImpl(T, LocalSize));
+ size_t LocalSize = TypeLoc(T, 0).castAs<TyLocType>().getLocalDataSize();
+ return pushImpl(T, LocalSize).castAs<TyLocType>();
}
/// Creates a TypeSourceInfo for the given type.