]> granicus.if.org Git - clang/commitdiff
Replace llvm::isPodLike<...> by llvm::is_trivially_copyable<...>
authorSerge Guelton <sguelton@quarkslab.com>
Sun, 20 Jan 2019 21:19:56 +0000 (21:19 +0000)
committerSerge Guelton <sguelton@quarkslab.com>
Sun, 20 Jan 2019 21:19:56 +0000 (21:19 +0000)
As noted in https://bugs.llvm.org/show_bug.cgi?id=36651, the specialization for
isPodLike<std::pair<...>> did not match the expectation of
std::is_trivially_copyable which makes the memcpy optimization invalid.

This patch renames the llvm::isPodLike trait into llvm::is_trivially_copyable.
Unfortunately std::is_trivially_copyable is not portable across compiler / STL
versions. So a portable version is provided too.

Note that the following specialization were invalid:

    std::pair<T0, T1>
    llvm::Optional<T>

Tests have been added to assert that former specialization are respected by the
standard usage of llvm::is_trivially_copyable, and that when a decent version
of std::is_trivially_copyable is available, llvm::is_trivially_copyable is
compared to std::is_trivially_copyable.

As of this patch, llvm::Optional is no longer considered trivially copyable,
even if T is. This is to be fixed in a later patch, as it has impact on a
long-running bug (see r347004)

Note that GCC warns about this UB, but this got silented by https://reviews.llvm.org/D50296.

Differential Revision: https://reviews.llvm.org/D54472

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

19 files changed:
include/clang/AST/BaseSubobject.h
include/clang/AST/CharUnits.h
include/clang/AST/DeclAccessPair.h
include/clang/AST/DeclarationName.h
include/clang/AST/ExprObjC.h
include/clang/AST/GlobalDecl.h
include/clang/AST/Type.h
include/clang/Analysis/ProgramPoint.h
include/clang/Basic/IdentifierTable.h
include/clang/Basic/SourceLocation.h
include/clang/Lex/Token.h
include/clang/Sema/CodeCompleteConsumer.h
include/clang/Sema/Ownership.h
include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
lib/AST/VTableBuilder.cpp
lib/Sema/SemaChecking.cpp
lib/StaticAnalyzer/Core/RegionStore.cpp
test/Analysis/llvm-conventions.cpp
tools/libclang/Indexing.cpp

index 151678fbd33c006683cb39fd12dbc0ae442bd561..15600f02fcefb7b3211cf9622102ed1c659c09ed 100644 (file)
@@ -80,11 +80,6 @@ template<> struct DenseMapInfo<clang::BaseSubobject> {
   }
 };
 
-// It's OK to treat BaseSubobject as a POD type.
-template <> struct isPodLike<clang::BaseSubobject> {
-  static const bool value = true;
-};
-
 } // namespace llvm
 
 #endif // LLVM_CLANG_AST_BASESUBOBJECT_H
index b029a1a3abbbb4848d8802285fdd85ed109b2fd5..37f489c7708ac2efb956abd9bc946a787bd30ddc 100644 (file)
@@ -237,10 +237,6 @@ template<> struct DenseMapInfo<clang::CharUnits> {
   }
 };
 
-template <> struct isPodLike<clang::CharUnits> {
-  static const bool value = true;
-};
-
 } // end namespace llvm
 
 #endif // LLVM_CLANG_AST_CHARUNITS_H
index 9b3337934153e6284daccca3582f98871ee6728b..805342c2910a7177a9f1403d8472a837c35b1b8f 100644 (file)
@@ -60,12 +60,4 @@ public:
 };
 }
 
-// Take a moment to tell SmallVector that DeclAccessPair is POD.
-namespace llvm {
-template<typename> struct isPodLike;
-template<> struct isPodLike<clang::DeclAccessPair> {
-   static const bool value = true;
-};
-}
-
 #endif
index 22f6bf7f44e9bd261bd131a82270101deeab8f1a..e5d34399f8dfa7c43df85d77a2a7d9f657828e7a 100644 (file)
@@ -861,9 +861,6 @@ struct DenseMapInfo<clang::DeclarationName> {
   }
 };
 
-template <>
-struct isPodLike<clang::DeclarationName> { static const bool value = true; };
-
 } // namespace llvm
 
 #endif // LLVM_CLANG_AST_DECLARATIONNAME_H
index b51935d0d7f75e46e7320c433d1694a1a1fcdf9f..debe5acebfd1f234b052178fde03801f9d8dcc9d 100644 (file)
@@ -255,12 +255,6 @@ struct ObjCDictionaryElement {
 
 } // namespace clang
 
-namespace llvm {
-
-template <> struct isPodLike<clang::ObjCDictionaryElement> : std::true_type {};
-
-} // namespace llvm
-
 namespace clang {
 
 /// Internal struct for storing Key/value pair.
index d6d8b110621848b5a0fb61795f98a780d71e30c0..a5937c239eafae6bee9b43803b371ec8476e9307 100644 (file)
@@ -139,13 +139,6 @@ namespace llvm {
     }
   };
 
-  // GlobalDecl isn't *technically* a POD type. However, its copy constructor,
-  // copy assignment operator, and destructor are all trivial.
-  template <>
-  struct isPodLike<clang::GlobalDecl> {
-    static const bool value = true;
-  };
-
 } // namespace llvm
 
 #endif // LLVM_CLANG_AST_GLOBALDECL_H
index 58e2f60fe764d1826f548ceea5b9773915c3f279..fbf91d3088c7d9aafbe33defe348e13e638ce09e 100644 (file)
@@ -94,9 +94,6 @@ namespace llvm {
     enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
   };
 
-  template <>
-  struct isPodLike<clang::QualType> { static const bool value = true; };
-
 } // namespace llvm
 
 namespace clang {
index 0f869233af6987adc4bc3d44203d28ddf65567f5..623f5dc7072b41c7a43d4cf0275842ac8c9e5979 100644 (file)
@@ -777,9 +777,6 @@ static bool isEqual(const clang::ProgramPoint &L,
 
 };
 
-template <>
-struct isPodLike<clang::ProgramPoint> { static const bool value = true; };
-
 } // end namespace llvm
 
 #endif
index c5ad0e583048fcb90c25c9935bc83d0ad85d0773..465486ede7151e8a15236073ea9803062a113b92 100644 (file)
@@ -938,9 +938,6 @@ struct DenseMapInfo<clang::Selector> {
   }
 };
 
-template <>
-struct isPodLike<clang::Selector> { static const bool value = true; };
-
 template<>
 struct PointerLikeTypeTraits<clang::Selector> {
   static const void *getAsVoidPointer(clang::Selector P) {
index 2b7f967d05263a7305972a7764306cce5c5e8bc9..ceebdf48225eb2a65d4f5c1678ec5d62d04d7677 100644 (file)
@@ -25,7 +25,6 @@
 namespace llvm {
 
 template <typename T> struct DenseMapInfo;
-template <typename T> struct isPodLike;
 
 } // namespace llvm
 
@@ -457,11 +456,6 @@ namespace llvm {
     }
   };
 
-  template <>
-  struct isPodLike<clang::SourceLocation> { static const bool value = true; };
-  template <>
-  struct isPodLike<clang::FileID> { static const bool value = true; };
-
   // Teach SmallPtrSet how to handle SourceLocation.
   template<>
   struct PointerLikeTypeTraits<clang::SourceLocation> {
index 83f4433709342630bae22d5bdb02d765e508d95d..20483e393c10f406ef3382d4222317523fde81af 100644 (file)
@@ -328,9 +328,4 @@ struct PPConditionalInfo {
 
 } // end namespace clang
 
-namespace llvm {
-  template <>
-  struct isPodLike<clang::Token> { static const bool value = true; };
-} // end namespace llvm
-
 #endif // LLVM_CLANG_LEX_TOKEN_H
index 005d62ad00c947fc8d92cda1e10343b9e94e8901..5c14fb87737a4cd9b73111eba3b601a05312232d 100644 (file)
@@ -655,14 +655,6 @@ public:
 
 } // namespace clang
 
-namespace llvm {
-
-template <> struct isPodLike<clang::CodeCompletionString::Chunk> {
-  static const bool value = true;
-};
-
-} // namespace llvm
-
 namespace clang {
 
 /// A builder class used to construct new code-completion strings.
index 8a82c1382d50aed3d6db92078820cc85ae25cd38..f395282c0c52c3d6a47cc21ff79eef89207e433a 100644 (file)
@@ -128,9 +128,6 @@ namespace llvm {
     }
   };
 
-  template <class T>
-  struct isPodLike<clang::OpaquePtr<T>> { static const bool value = true; };
-
 } // namespace llvm
 
 namespace clang {
index d956133d030fb8d725fe890f3d27d9a0fbb84740..e859936621d0beee3175154f729fee682fa98eff 100644 (file)
@@ -667,13 +667,4 @@ private:
 
 } // namespace clang
 
-namespace llvm {
-
-template <typename T> struct isPodLike;
-template <> struct isPodLike<clang::ento::SVal> {
-  static const bool value = true;
-};
-
-} // namespace llvm
-
 #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H
index d2701720e91eb2d19817f5293082c56a38b45e30..85c4fca378ecb1fe8724202d671b1e661fb9329f 100644 (file)
@@ -846,6 +846,8 @@ private:
       : BaseOffset(CharUnits::Zero()),
       BaseOffsetInLayoutClass(CharUnits::Zero()),
       VTableIndex(0) { }
+
+    MethodInfo(MethodInfo const&) = default;
   };
 
   typedef llvm::DenseMap<const CXXMethodDecl *, MethodInfo> MethodInfoMapTy;
index b3c3d7bbe9ff52bd6f8bf34982b15fb3943a63de..90c931f8844bccaab4e2d4b71adddbec66655226 100644 (file)
@@ -11662,12 +11662,12 @@ class SequenceChecker : public EvaluatedExprVisitor<SequenceChecker> {
     class Seq {
       friend class SequenceTree;
 
-      unsigned Index = 0;
+      unsigned Index;
 
       explicit Seq(unsigned N) : Index(N) {}
 
     public:
-      Seq() = default;
+      Seq() : Index(0) {}
     };
 
     SequenceTree() { Values.push_back(Value(0)); }
index c15c48cc46e8c88b145851bfa6e8999591425b97..679d95b7c589ac724d58d98e86b720a7afa6d3b8 100644 (file)
@@ -130,10 +130,6 @@ namespace llvm {
     return os;
   }
 
-  template <typename T> struct isPodLike;
-  template <> struct isPodLike<BindingKey> {
-    static const bool value = true;
-  };
 } // end llvm namespace
 
 #ifndef NDEBUG
index 49bdc6380bc82ef498a0a66ab4f7f4498cd7e0d5..e8588db60f430b4e4f08835e0a967e39397db609 100644 (file)
@@ -152,8 +152,6 @@ inline bool operator>(StringRef LHS, StringRef RHS);
 inline bool operator>=(StringRef LHS, StringRef RHS);
 inline std::string &operator+=(std::string &buffer, StringRef string);
 hash_code hash_value(StringRef S);
-template <typename T> struct isPodLike;
-template <> struct isPodLike<StringRef> { static const bool value = true; };
 
 } // end of namespace llvm
 
index 1833a80182452e25b3ea7d6ed34d180f2cd4e9c4..d666d4bff47fef5464dedbe9ba5b35eb7010206d 100644 (file)
@@ -93,9 +93,6 @@ typedef llvm::DenseSet<PPRegion> PPRegionSetTy;
 } // end anonymous namespace
 
 namespace llvm {
-  template <> struct isPodLike<PPRegion> {
-    static const bool value = true;
-  };
 
   template <>
   struct DenseMapInfo<PPRegion> {