[clang] a5b056f - [MSVC] Fix pragma alloc_text failing for C files
Stephen Long via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 1 09:40:05 PDT 2022
Author: Stephen Long
Date: 2022-06-01T09:39:46-07:00
New Revision: a5b056fe49a991c65e665468f1a681965f41b137
URL: https://github.com/llvm/llvm-project/commit/a5b056fe49a991c65e665468f1a681965f41b137
DIFF: https://github.com/llvm/llvm-project/commit/a5b056fe49a991c65e665468f1a681965f41b137.diff
LOG: [MSVC] Fix pragma alloc_text failing for C files
`isExternCContext()` is returning false for functions in C files
Reviewed By: rnk, aaron.ballman
Differential Revision: https://reviews.llvm.org/D126559
Added:
clang/test/Sema/pragma-ms-alloc-text.c
Modified:
clang/lib/Sema/SemaAttr.cpp
clang/test/Sema/pragma-ms-alloc-text.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 9681117abe424..4560bb060a4aa 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -763,7 +763,7 @@ void Sema::ActOnPragmaMSAllocText(
}
DeclContext *DC = ND->getDeclContext();
- if (!DC->isExternCContext()) {
+ if (getLangOpts().CPlusPlus && !DC->isExternCContext()) {
Diag(Loc, diag::err_pragma_alloc_text_c_linkage);
return;
}
diff --git a/clang/test/Sema/pragma-ms-alloc-text.c b/clang/test/Sema/pragma-ms-alloc-text.c
new file mode 100644
index 0000000000000..a5f2e9f11dce2
--- /dev/null
+++ b/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() {}
diff --git a/clang/test/Sema/pragma-ms-alloc-text.cpp b/clang/test/Sema/pragma-ms-alloc-text.cpp
index e1fb0ab4b2538..931b152fe78cc 100644
--- a/clang/test/Sema/pragma-ms-alloc-text.cpp
+++ b/clang/test/Sema/pragma-ms-alloc-text.cpp
@@ -34,3 +34,9 @@ void foo4() {}
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
diff erent language linkage}}
+
+extern "C" {
+static void foo6();
+#pragma alloc_text(c, foo6) // no-warning
+void foo6() {}
+}
More information about the cfe-commits
mailing list