This revision was automatically updated to reflect the committed changes. Closed by commit rGa5b056fe49a9: [MSVC] Fix pragma alloc_text failing for C files (authored by steplong).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D126559/new/ https://reviews.llvm.org/D126559 Files: 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 @@ -34,3 +34,9 @@ void foo5(); // expected-note {{previous declaration is here}} #pragma alloc_text(c, foo5) // expected-error {{'#pragma alloc_text' is applicable only to functions with C linkage}} extern "C" void foo5() {} // expected-error {{declaration of 'foo5' has a different language linkage}} + +extern "C" { +static void foo6(); +#pragma alloc_text(c, foo6) // no-warning +void foo6() {} +} Index: clang/test/Sema/pragma-ms-alloc-text.c =================================================================== --- /dev/null +++ clang/test/Sema/pragma-ms-alloc-text.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s + +void foo(); +#pragma alloc_text("hello", foo) // expected-no-diagnostics +void foo() {} + +static void foo1(); +#pragma alloc_text("hello", foo1) // expected-no-diagnostics +void foo1() {} Index: clang/lib/Sema/SemaAttr.cpp =================================================================== --- clang/lib/Sema/SemaAttr.cpp +++ clang/lib/Sema/SemaAttr.cpp @@ -763,7 +763,7 @@ } DeclContext *DC = ND->getDeclContext(); - if (!DC->isExternCContext()) { + if (getLangOpts().CPlusPlus && !DC->isExternCContext()) { Diag(Loc, diag::err_pragma_alloc_text_c_linkage); return; }
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 @@ -34,3 +34,9 @@ void foo5(); // expected-note {{previous declaration is here}} #pragma alloc_text(c, foo5) // expected-error {{'#pragma alloc_text' is applicable only to functions with C linkage}} extern "C" void foo5() {} // expected-error {{declaration of 'foo5' has a different language linkage}} + +extern "C" { +static void foo6(); +#pragma alloc_text(c, foo6) // no-warning +void foo6() {} +} Index: clang/test/Sema/pragma-ms-alloc-text.c =================================================================== --- /dev/null +++ clang/test/Sema/pragma-ms-alloc-text.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s + +void foo(); +#pragma alloc_text("hello", foo) // expected-no-diagnostics +void foo() {} + +static void foo1(); +#pragma alloc_text("hello", foo1) // expected-no-diagnostics +void foo1() {} Index: clang/lib/Sema/SemaAttr.cpp =================================================================== --- clang/lib/Sema/SemaAttr.cpp +++ clang/lib/Sema/SemaAttr.cpp @@ -763,7 +763,7 @@ } DeclContext *DC = ND->getDeclContext(); - if (!DC->isExternCContext()) { + if (getLangOpts().CPlusPlus && !DC->isExternCContext()) { Diag(Loc, diag::err_pragma_alloc_text_c_linkage); return; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits