[PATCH] D93102: [Clang][Sema] Detect section type conflicts between functions and variables

Tomas Matheson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 14 02:15:20 PST 2020


tmatheson updated this revision to Diff 311531.
tmatheson added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93102/new/

https://reviews.llvm.org/D93102

Files:
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Sema/attr-section.c


Index: clang/test/Sema/attr-section.c
===================================================================
--- clang/test/Sema/attr-section.c
+++ clang/test/Sema/attr-section.c
@@ -26,9 +26,17 @@
 
 // Not a warning.
 int c;
-int c __attribute__((section("foo,zed")));
+int c __attribute__((section("seg1,sec1")));
 
 // Also OK.
 struct r_debug {};
 extern struct r_debug _r_debug;
 struct r_debug _r_debug __attribute__((nocommon, section(".r_debug,bar")));
+
+// Section type conflicts between functions and variables
+void test3(void) __attribute__((section("seg2,sec2"))); // expected-note {{declared here}}
+void test3(void) {}
+const int ro __attribute__((section("seg2,sec2"))) = 10; // expected-error {{'ro' causes a section type conflict with 'test3'}}
+void test4(void) __attribute__((section("seg3,sec3"))); // expected-note {{declared here}}
+void test4(void) {}
+int rw __attribute__((section("seg3,sec3"))) = 10;       // expected-error {{'rw' causes a section type conflict with 'test4'}}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -3043,8 +3043,15 @@
   }
 
   SectionAttr *NewAttr = S.mergeSectionAttr(D, AL, Str);
-  if (NewAttr)
+  if (NewAttr) {
     D->addAttr(NewAttr);
+    if (auto FD = dyn_cast<FunctionDecl>(D))
+      if (auto SA = dyn_cast<SectionAttr>(NewAttr))
+        S.UnifySection(SA->getName(),
+                       ASTContext::PSF_Implicit | ASTContext::PSF_Execute |
+                           ASTContext::PSF_Read,
+                       FD);
+  }
 }
 
 // This is used for `__declspec(code_seg("segname"))` on a decl.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93102.311531.patch
Type: text/x-patch
Size: 1701 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201214/979d9772/attachment.bin>


More information about the cfe-commits mailing list