ObjCIvarRefExpr, ObjCPropertyRefExpr, ObjCMessageExpr>(Cond)) {
// FIXME: Handle MemberExpr.
return true;
+ } else if (const auto *CE = dyn_cast<CastExpr>(Cond)) {
+ QualType T = CE->getType();
+ while (true) {
+ if (T.isVolatileQualified())
+ return true;
+
+ if (!T->isAnyPointerType() && !T->isReferenceType())
+ break;
+
+ T = T->getPointeeType();
+ }
}
return false;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (x) are updated in the loop body [bugprone-infinite-loop]
}
}
+
+void test_volatile_cast() {
+ // This is a no-op cast. Clang ignores the qualifier, we should too.
+ for (int i = 0; (volatile int)i < 10;) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
+ }
+}
+
+void test_volatile_concrete_address(int i, int size) {
+ // No warning. The value behind the volatile concrete address
+ // is beyond our control. It may change at any time.
+ for (; *((volatile int *)0x1234) < size;) {
+ }
+
+ for (; *((volatile int *)(0x1234 + i)) < size;) {
+ }
+
+ for (; **((volatile int **)0x1234) < size;) {
+ }
+
+ volatile int *x = (volatile int *)0x1234;
+ for (; *x < 10;) {
+ }
+
+ // FIXME: This one should probably also be suppressed.
+ // Whatever the developer is doing here, they can do that again anywhere else
+ // which basically makes it a global.
+ for (; *(int *)0x1234 < size;) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (size) are updated in the loop body [bugprone-infinite-loop]
+ }
+}
}
}
}
+
+void volatile_concrete_address() {
+ // No warning. The value behind the volatile concrete address
+ // is beyond our control. It may change at any time.
+ if (*(volatile int *)0x1234) {
+ if (*(volatile int *)0x1234) {
+ doSomething();
+ }
+ }
+}