[PATCH] D48443: [WIP] Add no-prototype attribute to prototype-less C functions

Sam Clegg via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 21 10:09:35 PDT 2018


sbc100 updated this revision to Diff 152335.
sbc100 added a comment.

wrong test


Repository:
  rC Clang

https://reviews.llvm.org/D48443

Files:
  lib/CodeGen/CGCall.cpp
  test/CodeGen/no-prototype.c


Index: test/CodeGen/no-prototype.c
===================================================================
--- /dev/null
+++ test/CodeGen/no-prototype.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o - | FileCheck %s
+
+extern void foo();
+
+void bar(int a) {
+  foo(1);
+}
+
+// CHECK: declare void @foo(...) [[NOPROTO:#[0-9]+]]
+// CHECK: attributes [[NOPROTO]] = {  {{.*}}"no-prototype"{{.*}} }
Index: lib/CodeGen/CGCall.cpp
===================================================================
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -1845,6 +1845,8 @@
       FuncAttrs.addAttribute(llvm::Attribute::Convergent);
 
     if (const FunctionDecl *Fn = dyn_cast<FunctionDecl>(TargetDecl)) {
+      if (!AttrOnCallSite && !Fn->hasPrototype())
+        FuncAttrs.addAttribute("no-prototype");
       AddAttributesFromFunctionProtoType(
           getContext(), FuncAttrs, Fn->getType()->getAs<FunctionProtoType>());
       // Don't use [[noreturn]] or _Noreturn for a call to a virtual function.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48443.152335.patch
Type: text/x-patch
Size: 1040 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180621/ecc03d12/attachment.bin>


More information about the cfe-commits mailing list