[PATCH] D91828: [Sema/Attribute] Ignore noderef attribute in unevaluated context
Jann Horn via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 19 16:44:20 PST 2020
thejh updated this revision to Diff 306555.
thejh added a comment.
re-uploading to trigger a new build, since the build error looks unrelated.
maybe current trunk is flaky?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D91828/new/
https://reviews.llvm.org/D91828
Files:
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprMember.cpp
clang/test/Frontend/noderef.c
Index: clang/test/Frontend/noderef.c
===================================================================
--- clang/test/Frontend/noderef.c
+++ clang/test/Frontend/noderef.c
@@ -63,6 +63,12 @@
p = &s->a;
p = &(*s).b;
+ // Nothing in sizeof() actually accesses memory
+ x = sizeof(s->a); // ok
+ x = sizeof(*s); // ok
+ x = sizeof(s[0]); // ok
+ x = sizeof(s->a + (s->b)); // ok
+
// Nested struct access
struct S2 NODEREF *s2_noderef; // expected-note 5 {{s2_noderef declared here}}
p = s2_noderef->a; // ok since result is an array in a struct
Index: clang/lib/Sema/SemaExprMember.cpp
===================================================================
--- clang/lib/Sema/SemaExprMember.cpp
+++ clang/lib/Sema/SemaExprMember.cpp
@@ -1734,6 +1734,9 @@
}
void Sema::CheckMemberAccessOfNoDeref(const MemberExpr *E) {
+ if (isUnevaluatedContext())
+ return;
+
QualType ResultTy = E->getType();
// Do not warn on member accesses to arrays since this returns an array
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -4751,6 +4751,9 @@
}
void Sema::CheckSubscriptAccessOfNoDeref(const ArraySubscriptExpr *E) {
+ if (isUnevaluatedContext())
+ return;
+
QualType ResultTy = E->getType();
ExpressionEvaluationContextRecord &LastRecord = ExprEvalContexts.back();
@@ -14666,7 +14669,8 @@
OpLoc, CanOverflow, CurFPFeatureOverrides());
if (Opc == UO_Deref && UO->getType()->hasAttr(attr::NoDeref) &&
- !isa<ArrayType>(UO->getType().getDesugaredType(Context)))
+ !isa<ArrayType>(UO->getType().getDesugaredType(Context)) &&
+ !isUnevaluatedContext())
ExprEvalContexts.back().PossibleDerefs.insert(UO);
// Convert the result back to a half vector.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91828.306555.patch
Type: text/x-patch
Size: 1899 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201120/2ee877fa/attachment.bin>
More information about the cfe-commits
mailing list