[PATCH] D48443: 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:06:38 PDT 2018


sbc100 created this revision.
Herald added subscribers: cfe-commits, sunfish, aheejin, dschuff.

The WebAssembly backend in particular benefits from being
able to distinguish between varargs functions (...) and prototype-less
C functions.


Repository:
  rC Clang

https://reviews.llvm.org/D48443

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


Index: test/CodeGen/no-prototype.ll
===================================================================
--- /dev/null
+++ test/CodeGen/no-prototype.ll
@@ -0,0 +1,22 @@
+; ModuleID = '/usr/local/google/home/sbc/dev/wasm/llvm/tools/clang/test/CodeGen/prototypeless.c'
+source_filename = "/usr/local/google/home/sbc/dev/wasm/llvm/tools/clang/test/CodeGen/prototypeless.c"
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-darwin"
+
+; Function Attrs: noinline nounwind optnone
+define void @bar() #0 {
+entry:
+  call void (...) @foo()
+  ret void
+}
+
+declare void @foo(...) #1
+
+attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+
+!llvm.module.flags = !{!0}
+!llvm.ident = !{!1}
+
+!0 = !{i32 1, !"wchar_size", i32 4}
+!1 = !{!"clang version 7.0.0 (trunk 335193) (llvm/trunk 335137)"}
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.152334.patch
Type: text/x-patch
Size: 2234 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180621/e463dd91/attachment.bin>


More information about the cfe-commits mailing list