Skip to content

Commit

Permalink
Merged master:a26cd73d337 into amd-gfx:6931a9e8b3a
Browse files Browse the repository at this point in the history
Local branch amd-gfx 6931a9e Merged master:99b8f3570a3 into amd-gfx:7deeffc604f
Remote branch master a26cd73 [InstSimplify] add/move tests for or with not op (PR46083); NFC
  • Loading branch information
Sw authored and Sw committed Jun 3, 2020
2 parents 6931a9e + a26cd73 commit 4dd181d
Show file tree
Hide file tree
Showing 38 changed files with 571 additions and 1,278 deletions.
42 changes: 39 additions & 3 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12928,17 +12928,53 @@ class SequenceChecker : public ConstEvaluatedExprVisitor<SequenceChecker> {
}

void VisitCallExpr(const CallExpr *CE) {
// FIXME: CXXNewExpr and CXXDeleteExpr implicitly call functions.

if (CE->isUnevaluatedBuiltinCall(Context))
return;

// C++11 [intro.execution]p15:
// When calling a function [...], every value computation and side effect
// associated with any argument expression, or with the postfix expression
// designating the called function, is sequenced before execution of every
// expression or statement in the body of the function [and thus before
// the value computation of its result].
SequencedSubexpression Sequenced(*this);
SemaRef.runWithSufficientStackSpace(CE->getExprLoc(),
[&] { Base::VisitCallExpr(CE); });
SemaRef.runWithSufficientStackSpace(CE->getExprLoc(), [&] {
// C++17 [expr.call]p5
// The postfix-expression is sequenced before each expression in the
// expression-list and any default argument. [...]
SequenceTree::Seq CalleeRegion;
SequenceTree::Seq OtherRegion;
if (SemaRef.getLangOpts().CPlusPlus17) {
CalleeRegion = Tree.allocate(Region);
OtherRegion = Tree.allocate(Region);
} else {
CalleeRegion = Region;
OtherRegion = Region;
}
SequenceTree::Seq OldRegion = Region;

// FIXME: CXXNewExpr and CXXDeleteExpr implicitly call functions.
// Visit the callee expression first.
Region = CalleeRegion;
if (SemaRef.getLangOpts().CPlusPlus17) {
SequencedSubexpression Sequenced(*this);
Visit(CE->getCallee());
} else {
Visit(CE->getCallee());
}

// Then visit the argument expressions.
Region = OtherRegion;
for (const Expr *Argument : CE->arguments())
Visit(Argument);

Region = OldRegion;
if (SemaRef.getLangOpts().CPlusPlus17) {
Tree.merge(CalleeRegion);
Tree.merge(OtherRegion);
}
});
}

void VisitCXXConstructExpr(const CXXConstructExpr *CCE) {
Expand Down
22 changes: 21 additions & 1 deletion clang/test/SemaCXX/warn-unsequenced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ struct S {
int n;
};

// TODO: Implement the C++17 sequencing rules.
void test() {
int a;
int xs[10];
Expand Down Expand Up @@ -256,6 +255,27 @@ void test() {
p[i++] = (i = 42); // cxx11-warning {{multiple unsequenced modifications to 'i'}}
p++[i++] = (i = p ? i++ : i++); // cxx11-warning {{unsequenced modification and access to 'p'}}
// cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}

(i++, f)(i++, 42); // cxx11-warning {{multiple unsequenced modifications to 'i'}}
(i++ + i++, f)(42, 42); // cxx11-warning {{multiple unsequenced modifications to 'i'}}
// cxx17-warning@-1 {{multiple unsequenced modifications to 'i'}}
int (*pf)(int, int);
(pf = f)(pf != nullptr, pf != nullptr); // cxx11-warning {{unsequenced modification and access to 'pf'}}
pf((pf = f) != nullptr, 42); // cxx11-warning {{unsequenced modification and access to 'pf'}}
f((pf = f, 42), (pf = f, 42)); // cxx11-warning {{multiple unsequenced modifications to 'pf'}}
// cxx17-warning@-1 {{multiple unsequenced modifications to 'pf'}}
pf((pf = f) != nullptr, pf == nullptr); // cxx11-warning {{unsequenced modification and access to 'pf'}}
// cxx17-warning@-1 {{unsequenced modification and access to 'pf'}}
}

namespace PR20819 {
struct foo { void bar(int); };
foo get_foo(int);

void g() {
int a = 0;
get_foo(a).bar(a++); // cxx11-warning {{unsequenced modification and access to 'a'}}
}
}

namespace members {
Expand Down
Loading

0 comments on commit 4dd181d

Please sign in to comment.