diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -5772,8 +5772,8 @@ if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &ArgLoc)) return; - FD->addAttr(::new (S.Context) - WebAssemblyExportNameAttr(S.Context, AL, Str)); + D->addAttr(::new (S.Context) WebAssemblyExportNameAttr(S.Context, AL, Str)); + D->addAttr(UsedAttr::CreateImplicit(S.Context)); } static void handleWebAssemblyImportModuleAttr(Sema &S, Decl *D, const ParsedAttr &AL) { diff --git a/clang/test/CodeGen/wasm-export-name.c b/clang/test/CodeGen/wasm-export-name.c --- a/clang/test/CodeGen/wasm-export-name.c +++ b/clang/test/CodeGen/wasm-export-name.c @@ -6,6 +6,8 @@ return 43; } +// CHECK: @llvm.used = appending global [1 x i8*] [i8* bitcast (i32 ()* @foo to i8*)] + // CHECK: define i32 @foo() [[A:#[0-9]+]] // CHECK: attributes [[A]] = {{{.*}} "wasm-export-name"="bar" {{.*}}}