[clang] 2993243 - Fix misdiagnosed writability for __attribute__((section()))
David Blaikie via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 16 22:35:48 PDT 2023
Author: David Blaikie
Date: 2023-08-17T05:35:40Z
New Revision: 2993243c45abdb4f2bc3979336d054be165b1134
URL: https://github.com/llvm/llvm-project/commit/2993243c45abdb4f2bc3979336d054be165b1134
DIFF: https://github.com/llvm/llvm-project/commit/2993243c45abdb4f2bc3979336d054be165b1134.diff
LOG: Fix misdiagnosed writability for __attribute__((section()))
This didn't actually misclassify the resulting IR variable, but caused a
false-positive error about mismatched section flags.
Follow-up to D156726, issue identified by @eddyz87, thanks!
Added:
Modified:
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/attr-section.c
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 0ad807cca36c7b..3c2c7575ed9980 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -14363,8 +14363,8 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
bool MSVCEnv =
Context.getTargetInfo().getTriple().isWindowsMSVCEnvironment();
std::optional<QualType::NonConstantStorageReason> Reason;
- if (var->hasInit() && HasConstInit && !(Reason =
- var->getType().isNonConstantStorage(Context, true, false))) {
+ if (HasConstInit &&
+ !(Reason = var->getType().isNonConstantStorage(Context, true, false))) {
Stack = &ConstSegStack;
} else {
SectionFlags |= ASTContext::PSF_Write;
diff --git a/clang/test/Sema/attr-section.c b/clang/test/Sema/attr-section.c
index 1f058c24f980fd..2f9ac2f1ce9442 100644
--- a/clang/test/Sema/attr-section.c
+++ b/clang/test/Sema/attr-section.c
@@ -28,6 +28,9 @@ extern int a __attribute__((section("foo,zed"))); // expected-warning {{section
int c;
int c __attribute__((section("seg1,sec1")));
+const int with_init __attribute__((section("init_mix,x"))) = 1;
+const int no_init __attribute__((section("init_mix,x")));
+
// Also OK.
struct r_debug {};
extern struct r_debug _r_debug;
More information about the cfe-commits
mailing list