[PATCH] D77374: Fix -fsanitize=array-bounds with comma operator

Vitaly Buka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 3 02:07:29 PDT 2020


vitalybuka updated this revision to Diff 254728.
vitalybuka added a comment.

remove debug dump


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77374

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGen/bounds-checking.c
  clang/test/CodeGen/bounds-checking.cpp


Index: clang/test/CodeGen/bounds-checking.cpp
===================================================================
--- clang/test/CodeGen/bounds-checking.cpp
+++ clang/test/CodeGen/bounds-checking.cpp
@@ -98,3 +98,19 @@
   return s->a[i];
   // CHECK: }
 }
+
+// CHECK-LABEL: define {{.*}} @_Z10SFlexComma
+int SFlexComma(struct SFlex *s, int i) {
+  // a and b are treated as flexible array members.
+  // CHECK-NOT: @llvm.trap
+  return (s->t, s->a)[i];
+  // CHECK: }
+}
+
+// CHECK-LABEL: define {{.*}} @_Z7S1Comma
+int S1Comma(struct S1 *s, int i) {
+  // a and b are treated as flexible array members.
+  // CHECK-NOT: @llvm.trap
+  return ((s->t, (1, s->a)))[i];
+  // CHECK: }
+}
Index: clang/test/CodeGen/bounds-checking.c
===================================================================
--- clang/test/CodeGen/bounds-checking.c
+++ clang/test/CodeGen/bounds-checking.c
@@ -100,3 +100,19 @@
   return s->a[i];
   // CHECK: }
 }
+
+// CHECK-LABEL: define {{.*}} @SFlexComma
+int SFlexComma(struct SFlex *s, int i) {
+  // a and b are treated as flexible array members.
+  // CHECK-NOT: @llvm.trap
+  return (s->t, s->a)[i];
+  // CHECK: }
+}
+
+// CHECK-LABEL: define {{.*}} @S1Comma
+int S1Comma(struct S1 *s, int i) {
+  // a and b are treated as flexible array members.
+  // CHECK-NOT: @llvm.trap
+  return (s->t, s->a)[i];
+  // CHECK: }
+}
Index: clang/lib/CodeGen/CGExpr.cpp
===================================================================
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -879,6 +879,13 @@
 
   E = E->IgnoreParens();
 
+  while (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
+    if (!BO->isCommaOp())
+      break;
+    E = BO->getRHS();
+    E = E->IgnoreParens();
+  }
+
   // A flexible array member must be the last member in the class.
   if (const auto *ME = dyn_cast<MemberExpr>(E)) {
     // FIXME: If the base type of the member expr is not FD->getParent(),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77374.254728.patch
Type: text/x-patch
Size: 1938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200403/5542e15c/attachment-0001.bin>


More information about the cfe-commits mailing list