[PATCH] D126559: [MSVC] Fix pragma alloc_text failing for C files

Stephen Long via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 1 09:40:10 PDT 2022


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;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126559.433435.patch
Type: text/x-patch
Size: 1486 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220601/b4e3640d/attachment.bin>


More information about the cfe-commits mailing list