[PATCH] D77374: Fix -fsanitize=array-bounds with comma operator
Vitaly Buka via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 4 02:30:38 PDT 2020
vitalybuka updated this revision to Diff 255016.
vitalybuka added a comment.
try arc diff
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.255016.patch
Type: text/x-patch
Size: 1938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200404/a89283f2/attachment.bin>
More information about the cfe-commits
mailing list