[PATCH] D36294: CFI: blacklist STL allocate() from unrelated-casts

Peter Collingbourne via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 3 16:30:37 PDT 2017


pcc added a subscriber: cfe-commits.
pcc added inline comments.


================
Comment at: lib/CodeGen/CodeGenFunction.cpp:785
 
+  // Ignore unrelated casts from C++ calls to allocate(). Don't match on the
+  // namespace because not all allocators are in std::
----------------
The comment should explain why.


================
Comment at: lib/CodeGen/CodeGenFunction.cpp:789
+    auto *MD = dyn_cast_or_null<CXXMethodDecl>(D);
+    if (MD && MD->getName().equals("allocate") && MD->getNumParams() == 2) {
+      auto *BT = MD->parameters()[0]->getType()->getAs<BuiltinType>();
----------------
Should this also match the C++17 allocate function which takes a single argument?


================
Comment at: lib/CodeGen/CodeGenFunction.cpp:794
+          PT->getPointeeType().isConstQualified() &&
+          (BT->getKind() == BuiltinType::UInt ||
+           BT->getKind() == BuiltinType::ULong))
----------------
Maybe better to compare against `ASTContext::getSizeType()`, which should return the builtin type that corresponds to `size_t`.


https://reviews.llvm.org/D36294





More information about the cfe-commits mailing list