[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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@335510 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Sam Clegg 2018-06-25 18:47:32 +00:00
parent 7f4f83642f
commit f3b7928366
2 changed files with 29 additions and 0 deletions

View File

@ -747,6 +747,15 @@ class WebAssemblyTargetCodeGenInfo final : public TargetCodeGenInfo {
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.

View File

@ -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"{{.*}} }