This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGf382545b2ba8: [clang-cl] Handle some pragma alloc_text corner cases handled by MSVC (authored by steplong).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D128649/new/ https://reviews.llvm.org/D128649 Files: clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Sema/SemaAttr.cpp clang/test/Sema/pragma-ms-alloc-text.c clang/test/Sema/pragma-ms-alloc-text.cpp Index: clang/test/Sema/pragma-ms-alloc-text.cpp =================================================================== --- clang/test/Sema/pragma-ms-alloc-text.cpp +++ clang/test/Sema/pragma-ms-alloc-text.cpp @@ -40,3 +40,20 @@ #pragma alloc_text(c, foo6) // no-warning void foo6() {} } + +extern "C" { +static void foo7(); +} +static void foo7(); +#pragma alloc_text(c, foo7) // no-warning +void foo7() {} + +static void foo8(); +extern "C" { +static void foo8(); +} +#pragma alloc_text(c, foo8) // expected-error {{'#pragma alloc_text' is applicable only to functions with C linkage}} +void foo8() {} + +enum foo9 { A, B, C }; +#pragma alloc_text(c, foo9) // expected-error {{'#pragma alloc_text' is applicable only to functions}} Index: clang/test/Sema/pragma-ms-alloc-text.c =================================================================== --- clang/test/Sema/pragma-ms-alloc-text.c +++ clang/test/Sema/pragma-ms-alloc-text.c @@ -1,9 +1,12 @@ // RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s void foo(); -#pragma alloc_text("hello", foo) // expected-no-diagnostics +#pragma alloc_text("hello", foo) // no-error void foo() {} static void foo1(); -#pragma alloc_text("hello", foo1) // expected-no-diagnostics +#pragma alloc_text("hello", foo1) // no-error void foo1() {} + +int foo2; +#pragma alloc_text(c, foo2) // expected-error {{'#pragma alloc_text' is applicable only to functions}} Index: clang/lib/Sema/SemaAttr.cpp =================================================================== --- clang/lib/Sema/SemaAttr.cpp +++ clang/lib/Sema/SemaAttr.cpp @@ -810,8 +810,13 @@ return; } - DeclContext *DC = ND->getDeclContext(); - if (getLangOpts().CPlusPlus && !DC->isExternCContext()) { + auto *FD = dyn_cast<FunctionDecl>(ND->getCanonicalDecl()); + if (!FD) { + Diag(Loc, diag::err_pragma_alloc_text_not_function); + return; + } + + if (getLangOpts().CPlusPlus && !FD->isInExternCContext()) { Diag(Loc, diag::err_pragma_alloc_text_c_linkage); return; } Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -992,6 +992,8 @@ "'#pragma %0' can only appear at file scope">; def err_pragma_alloc_text_c_linkage: Error< "'#pragma alloc_text' is applicable only to functions with C linkage">; +def err_pragma_alloc_text_not_function: Error< + "'#pragma alloc_text' is applicable only to functions">; def warn_pragma_unused_undeclared_var : Warning< "undeclared variable %0 used as an argument for '#pragma unused'">,
Index: clang/test/Sema/pragma-ms-alloc-text.cpp =================================================================== --- clang/test/Sema/pragma-ms-alloc-text.cpp +++ clang/test/Sema/pragma-ms-alloc-text.cpp @@ -40,3 +40,20 @@ #pragma alloc_text(c, foo6) // no-warning void foo6() {} } + +extern "C" { +static void foo7(); +} +static void foo7(); +#pragma alloc_text(c, foo7) // no-warning +void foo7() {} + +static void foo8(); +extern "C" { +static void foo8(); +} +#pragma alloc_text(c, foo8) // expected-error {{'#pragma alloc_text' is applicable only to functions with C linkage}} +void foo8() {} + +enum foo9 { A, B, C }; +#pragma alloc_text(c, foo9) // expected-error {{'#pragma alloc_text' is applicable only to functions}} Index: clang/test/Sema/pragma-ms-alloc-text.c =================================================================== --- clang/test/Sema/pragma-ms-alloc-text.c +++ clang/test/Sema/pragma-ms-alloc-text.c @@ -1,9 +1,12 @@ // RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s void foo(); -#pragma alloc_text("hello", foo) // expected-no-diagnostics +#pragma alloc_text("hello", foo) // no-error void foo() {} static void foo1(); -#pragma alloc_text("hello", foo1) // expected-no-diagnostics +#pragma alloc_text("hello", foo1) // no-error void foo1() {} + +int foo2; +#pragma alloc_text(c, foo2) // expected-error {{'#pragma alloc_text' is applicable only to functions}} Index: clang/lib/Sema/SemaAttr.cpp =================================================================== --- clang/lib/Sema/SemaAttr.cpp +++ clang/lib/Sema/SemaAttr.cpp @@ -810,8 +810,13 @@ return; } - DeclContext *DC = ND->getDeclContext(); - if (getLangOpts().CPlusPlus && !DC->isExternCContext()) { + auto *FD = dyn_cast<FunctionDecl>(ND->getCanonicalDecl()); + if (!FD) { + Diag(Loc, diag::err_pragma_alloc_text_not_function); + return; + } + + if (getLangOpts().CPlusPlus && !FD->isInExternCContext()) { Diag(Loc, diag::err_pragma_alloc_text_c_linkage); return; } Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -992,6 +992,8 @@ "'#pragma %0' can only appear at file scope">; def err_pragma_alloc_text_c_linkage: Error< "'#pragma alloc_text' is applicable only to functions with C linkage">; +def err_pragma_alloc_text_not_function: Error< + "'#pragma alloc_text' is applicable only to functions">; def warn_pragma_unused_undeclared_var : Warning< "undeclared variable %0 used as an argument for '#pragma unused'">,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits