r335510 - [WebAssembly] Add no-prototype attribute to prototype-less C functions

Sam Clegg via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 25 11:47:32 PDT 2018


Author: sbc
Date: Mon Jun 25 11:47:32 2018
New Revision: 335510

URL: http://llvm.org/viewvc/llvm-project?rev=335510&view=rev
Log:
[WebAssembly] Add no-prototype attribute to prototype-less C functions

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

Differential Revision: https://reviews.llvm.org/D48443

Added:
    cfe/trunk/test/CodeGen/no-prototype.c   (with props)
Modified:
    cfe/trunk/lib/CodeGen/TargetInfo.cpp

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=335510&r1=335509&r2=335510&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Mon Jun 25 11:47:32 2018
@@ -747,6 +747,15 @@ class WebAssemblyTargetCodeGenInfo final
 public:
   explicit WebAssemblyTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
       : TargetCodeGenInfo(new WebAssemblyABIInfo(CGT)) {}
+
+  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+                           CodeGen::CodeGenModule &CGM) const override {
+    if (auto *FD = dyn_cast_or_null<FunctionDecl>(D)) {
+      llvm::Function *Fn = cast<llvm::Function>(GV);
+      if (!FD->doesThisDeclarationHaveABody() && !FD->hasPrototype())
+        Fn->addFnAttr("no-prototype");
+    }
+  }
 };
 
 /// Classify argument of given type \p Ty.

Added: cfe/trunk/test/CodeGen/no-prototype.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/no-prototype.c?rev=335510&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/no-prototype.c (added)
+++ cfe/trunk/test/CodeGen/no-prototype.c Mon Jun 25 11:47:32 2018
@@ -0,0 +1,20 @@
+// REQUIRES: webassembly-registered-target
+// RUN: %clang_cc1 -triple wasm32 -emit-llvm %s -o - | FileCheck %s
+
+int foo();
+
+int bar(int a) {
+  return foo();
+}
+
+int baz() {
+  return foo();
+}
+
+// CHECK: define i32 @bar(i32 %a) [[BAR_ATTR:#[0-9]+]] {
+// CHECK: declare i32 @foo(...) [[FOO_ATTR:#[0-9]+]]
+// CHECK: define i32 @baz() [[BAZ_ATTR:#[0-9]+]] {
+
+// CHECK: attributes [[FOO_ATTR]] = {  {{.*}}"no-prototype"{{.*}} }
+// CHECK-NOT: attributes [[BAR_ATTR]] = {  {{.*}}"no-prototype"{{.*}} }
+// CHECK-NOT: attributes [[BAZ_ATTR]] = {  {{.*}}"no-prototype"{{.*}} }

Propchange: cfe/trunk/test/CodeGen/no-prototype.c
------------------------------------------------------------------------------
    svn:eol-style = LF




More information about the cfe-commits mailing list