[PATCH] Implement the __builtin_call_with_static_chain GNU extension.

Richard Smith richard at metafoo.co.uk
Tue Dec 9 18:10:04 PST 2014


================
Comment at: include/clang/Basic/Builtins.def:500
@@ -499,2 +499,3 @@
 BUILTIN(__builtin_alloca, "v*z"   , "n")
+BUILTIN(__builtin_call_with_static_chain, "v.", "t")
 
----------------
This should presumably also be marked "n"; it itself never throws (its argument might, but that's a separate issue).

================
Comment at: lib/Sema/SemaChecking.cpp:177-184
@@ +176,10 @@
+
+  ExprResult ChainResult = S.UsualUnaryConversions(Chain);
+  if (ChainResult.isInvalid())
+    return true;
+  if (!ChainResult.get()->getType()->isPointerType()) {
+    S.Diag(BuiltinLoc, diag::err_second_argument_to_cwsc_not_pointer)
+        << Chain->getSourceRange();
+    return true;
+  }
+
----------------
It might be better to perform conversions as if to a parameter of type `void *` here (that would be detectable in C++ via conversion operators, and would do the right thing for null pointer constants). What does GCC do in those cases?

================
Comment at: lib/Sema/SemaChecking.cpp:187
@@ +186,3 @@
+  BuiltinCall->setType(CE->getType());
+  BuiltinCall->getCallee()->setType(CE->getCallee()->getType());
+  BuiltinCall->setValueKind(CE->getValueKind());
----------------
This can't be right: multiple calls to the builtin will share the same callee and will want different types here. Just remove this line?

http://reviews.llvm.org/D6332






More information about the cfe-commits mailing list