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

Stephen Long via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 27 10:32:19 PDT 2022


steplong created this revision.
Herald added a project: All.
steplong requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

`isExternCContext()` is returning false for functions in C files

Change-Id: I51cccb476aa19dc0a0a78e951d7f482befdb78ca


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126559

Files:
  clang/lib/Sema/SemaAttr.cpp
  clang/test/Sema/pragma-ms-alloc-text.c


Index: clang/test/Sema/pragma-ms-alloc-text.c
===================================================================
--- /dev/null
+++ clang/test/Sema/pragma-ms-alloc-text.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s
+
+void foo();
+#pragma alloc_text("hello", foo) // expected-no-diagnostics
+void foo() {}
Index: clang/lib/Sema/SemaAttr.cpp
===================================================================
--- clang/lib/Sema/SemaAttr.cpp
+++ clang/lib/Sema/SemaAttr.cpp
@@ -762,8 +762,8 @@
       return;
     }
 
-    DeclContext *DC = ND->getDeclContext();
-    if (!DC->isExternCContext()) {
+    FunctionDecl *FD = ND->getAsFunction();
+    if (!FD->isExternC()) {
       Diag(Loc, diag::err_pragma_alloc_text_c_linkage);
       return;
     }


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


More information about the cfe-commits mailing list