PR21706: -Wunsequenced was missing warnings when leaving a sequenced region that contained side effects.

llvm-svn: 223184
This commit is contained in:
Richard Smith 2014-12-03 01:05:50 +00:00
parent 4a5697e659
commit e8efd99b24
2 changed files with 13 additions and 7 deletions

View File

@ -7014,11 +7014,12 @@ class SequenceChecker : public EvaluatedExprVisitor<SequenceChecker> {
Self.ModAsSideEffect = &ModAsSideEffect;
}
~SequencedSubexpression() {
for (unsigned I = 0, E = ModAsSideEffect.size(); I != E; ++I) {
UsageInfo &U = Self.UsageMap[ModAsSideEffect[I].first];
U.Uses[UK_ModAsSideEffect] = ModAsSideEffect[I].second;
Self.addUsage(U, ModAsSideEffect[I].first,
ModAsSideEffect[I].second.Use, UK_ModAsValue);
for (auto MI = ModAsSideEffect.rbegin(), ME = ModAsSideEffect.rend();
MI != ME; ++MI) {
UsageInfo &U = Self.UsageMap[MI->first];
auto &SideEffectUsage = U.Uses[UK_ModAsSideEffect];
Self.addUsage(U, MI->first, SideEffectUsage.Use, UK_ModAsValue);
SideEffectUsage = MI->second;
}
Self.ModAsSideEffect = OldModAsSideEffect;
}

View File

@ -29,6 +29,11 @@ void test() {
a = f(a++, 0); // ok
a = f(++a, a++); // expected-warning {{multiple unsequenced modifications}}
++a + f(++a, 0); // expected-warning {{multiple unsequenced modifications}}
f(++a, 0) + ++a; // expected-warning {{multiple unsequenced modifications}}
a++ + f(a++, 0); // expected-warning {{multiple unsequenced modifications}}
f(a++, 0) + a++; // expected-warning {{multiple unsequenced modifications}}
a = ++a; // expected-warning {{multiple unsequenced modifications}}
a += ++a; // expected-warning {{unsequenced modification and access}}
@ -48,7 +53,7 @@ void test() {
(1 ? a : ++a) + a; // ok
(xs[5] ? ++a : ++a) + a; // FIXME: warn here
(++a, xs[6] ? ++a : 0) + a; // FIXME: warn here
(++a, xs[6] ? ++a : 0) + a; // expected-warning {{unsequenced modification and access}}
// Here, the read of the fourth 'a' might happen before or after the write to
// the second 'a'.
@ -84,5 +89,5 @@ void test() {
(__builtin_classify_type(++a) ? 1 : 0) + ++a; // ok
(__builtin_constant_p(++a) ? 1 : 0) + ++a; // ok
(__builtin_expect(++a, 0) ? 1 : 0) + ++a; // FIXME: warn here
(__builtin_expect(++a, 0) ? 1 : 0) + ++a; // expected-warning {{multiple unsequenced modifications}}
}