[PATCH] D102502: [clang] Fix ternary operator in second for loop argument

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 14 09:25:02 PDT 2021


rsmith added a comment.

Thanks, nice catch!

Can we also add an assert when parsing a `for` statement that we actually find a range if the tentative parse said we were expecting one?



================
Comment at: clang/test/CodeGenCXX/for-loop-init-ternary-operator-statement.cpp:1
+// RUN: %clang_cc1 -triple i386-unknown-unknown -O3 -emit-llvm -o - %s | FileCheck %s
+
----------------
We don't use `-O3` tests for this kind of thing, to avoid depending on the behaviour of the optimizer; instead you should test that the (unoptimized) IR generated by clang is correct.


================
Comment at: clang/test/PCH/for-loop-init-ternary-operator-statement.cpp:5
+int f() {
+  // CHECK: for (int i = 0; x; i++) {
+  for (int i = 0; int x = i < 2 ? 1 : 0; i++) {
----------------
This ast-print output looks wrong; I assume that's an unrelated bug?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102502/new/

https://reviews.llvm.org/D102502



More information about the cfe-commits mailing list