[PATCH] D43047: [Builtins] Overload __builtin_operator_new/delete to accept an optional alignment parameter.

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 7 15:14:29 PST 2018


rsmith added inline comments.


================
Comment at: lib/CodeGen/CGExprCXX.cpp:1309-1344
 RValue CodeGenFunction::EmitBuiltinNewDeleteCall(const FunctionProtoType *Type,
-                                                 const Expr *Arg,
-                                                 bool IsDelete) {
+                                                 const Expr *E, bool IsDelete) {
+  const auto *TheCall = dyn_cast<CallExpr>(E);
+  llvm::SmallVector<QualType, 2> ArgTypes;
+  for (auto *Arg : TheCall->arguments())
+    ArgTypes.push_back(Arg->getType());
   CallArgList Args;
----------------
Can we leave this code alone and set the builtin expression's type to exactly match the type of the chosen function? I really don't want to be special-casing aligned allocation here. (This change should also cover sized delete and any future extensions to builtin operator new/delete.)


================
Comment at: lib/Lex/PPMacroExpansion.cpp:1242-1243
+      // Clang specific changes which libc++ needs to be able to detect
+      .Case("has_aligned_builtin_operator_new",
+            LangOpts.CPlusPlus && LangOpts.AlignedAllocation)
+
----------------
Hmm, I'd prefer something that just indicates that we have generalized `__builtin_operator_new/delete` support, so that you can use it for sized delete too.


================
Comment at: lib/Sema/SemaChecking.cpp:2918-2962
+  if (TheCall->getNumArgs() < 1) {
+    Diag(TheCall->getLocEnd(), diag::err_typecheck_call_too_few_args)
+        << 0 << 1 << TheCall->getNumArgs()
+        << TheCall->getCallee()->getSourceRange();
+    return ExprError();
+  } else if (TheCall->getNumArgs() > 2) {
+    Diag(TheCall->getArg(2)->getLocStart(),
----------------
Here's how I think this should work:

 * perform overload resolution for an `operator new` or `operator delete` with the given arguments
 * if the selected function is not a usual allocation / deallocation function, issue an error
 * set the type of the callee expression to the type of the selected function and convert the parameters as if you were going to call the selected function (so that codegen can find the correct callee again)


https://reviews.llvm.org/D43047





More information about the cfe-commits mailing list