From 4b4726ef9aa0f64789856b07b04eb55a14401cd9 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Mon, 7 Dec 2015 20:04:57 +0000 Subject: [PATCH] AST: defer to TypeLoc::copy in TypeLoc::initializeFullCopy 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 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/include/clang/AST/TypeLoc.h b/include/clang/AST/TypeLoc.h index 674fffb8fa..26feda5d76 100644 --- a/include/clang/AST/TypeLoc.h +++ b/include/clang/AST/TypeLoc.h @@ -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. -- 2.40.0