[PATCH] D40218: [Clang] Add __builtin_launder

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 7 15:03:00 PST 2017


rsmith added inline comments.


================
Comment at: lib/CodeGen/CGBuiltin.cpp:1674
+    Value *Ptr = EmitScalarExpr(E->getArg(0));
+    Ptr = Builder.CreateInvariantGroupBarrier(Ptr);
+    return RValue::get(Ptr);
----------------
It would be nice to avoid this for types that contain no const subobjects / reference subobjects / vptrs. I think we can also omit this entirely if `-fstrict-vtable-ptrs` is disabled, since in that case we don't generate any `invariant.group` metadata.

I'd be OK with the former being left to a future change, but the latter should be part of this change so we don't generate unnecessarily-inefficient code in the default mode for uses of `std::launder`.


================
Comment at: lib/Sema/SemaChecking.cpp:860-864
+  if (!ArgTy->isPointerType()) {
+    S.Diag(TheCall->getLocStart(), diag::err_builtin_launder_non_pointer_arg)
+        << TheCall->getSourceRange();
+    return ExprError();
+  }
----------------
Please also check that the pointee type is an object type -- per [ptr.launder]p3, "the program is ill-formed if T is a function type or cv void", and we don't want our builtin to need to deal with such cases.


https://reviews.llvm.org/D40218





More information about the cfe-commits mailing list