diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp --- a/clang/lib/Sema/SemaExpr.cpp +++ b/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(UO->getType().getDesugaredType(Context))) + !isa(UO->getType().getDesugaredType(Context)) && + !isUnevaluatedContext()) ExprEvalContexts.back().PossibleDerefs.insert(UO); // Convert the result back to a half vector. diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp --- a/clang/lib/Sema/SemaExprMember.cpp +++ b/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 diff --git a/clang/test/Frontend/noderef.c b/clang/test/Frontend/noderef.c --- a/clang/test/Frontend/noderef.c +++ b/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