]> granicus.if.org Git - clang/commitdiff
AST: defer to TypeLoc::copy in TypeLoc::initializeFullCopy
authorJustin Bogner <mail@justinbogner.com>
Mon, 7 Dec 2015 20:04:57 +0000 (20:04 +0000)
committerJustin Bogner <mail@justinbogner.com>
Mon, 7 Dec 2015 20:04:57 +0000 (20:04 +0000)
If we're initializing a TypeLoc from one that's been allocated with
different alignment, memcpy will get the padding wrong. The `copy`
method already checks and handles this case, so we should just defer
to it.

This also drops the `const` off of the `initializeFullCopy`
declarations, since it isn't even remotely true (and the compiler
notices when we try to call copy() instead of tricking it with
memcpy).

Fixes llvm.org/pr23516.

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

include/clang/AST/TypeLoc.h

index 674fffb8fa259858250235079436bbb6bab6fb5a..26feda5d7668f297dd66a4168eef9d403ccb4fa6 100644 (file)
@@ -170,19 +170,18 @@ public:
 
   /// \brief Initializes this by copying its information from another
   /// TypeLoc of the same type.
-  void initializeFullCopy(TypeLoc Other) const {
+  void initializeFullCopy(TypeLoc Other) {
     assert(getType() == Other.getType());
-    size_t Size = getFullDataSize();
-    memcpy(getOpaqueData(), Other.getOpaqueData(), Size);
+    copy(Other);
   }
 
   /// \brief Initializes this by copying its information from another
   /// TypeLoc of the same type.  The given size must be the full data
   /// size.
-  void initializeFullCopy(TypeLoc Other, unsigned Size) const {
+  void initializeFullCopy(TypeLoc Other, unsigned Size) {
     assert(getType() == Other.getType());
     assert(getFullDataSize() == Size);
-    memcpy(getOpaqueData(), Other.getOpaqueData(), Size);
+    copy(Other);
   }
 
   /// Copies the other type loc into this one.