[clang] e98cbb9 - [CodeGenCXX] Add test for forward declare as array elem (NFC)
Nikita Popov via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 13 05:26:40 PDT 2023
Author: Nikita Popov
Date: 2023-07-13T14:26:25+02:00
New Revision: e98cbb95b8b96d3908a808bbcd639680a5197428
URL: https://github.com/llvm/llvm-project/commit/e98cbb95b8b96d3908a808bbcd639680a5197428
DIFF: https://github.com/llvm/llvm-project/commit/e98cbb95b8b96d3908a808bbcd639680a5197428.diff
LOG: [CodeGenCXX] Add test for forward declare as array elem (NFC)
To guard against the miscompile that D153142 would have introduced.
Added:
clang/test/CodeGenCXX/forward-declare-as-array-elem.cpp
Modified:
Removed:
################################################################################
diff --git a/clang/test/CodeGenCXX/forward-declare-as-array-elem.cpp b/clang/test/CodeGenCXX/forward-declare-as-array-elem.cpp
new file mode 100644
index 00000000000000..0d76e32b44cb27
--- /dev/null
+++ b/clang/test/CodeGenCXX/forward-declare-as-array-elem.cpp
@@ -0,0 +1,20 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s
+
+struct S;
+extern S a[10];
+S(*b)[10] = &a;
+struct S {
+ int x;
+};
+
+// The address calculation should be based on the size of the struct S
+// declaration, not a dummy type like i8.
+
+// CHECK-LABEL: define dso_local noundef i32 @_Z1fv
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr getelementptr inbounds ([10 x %struct.S], ptr @a, i64 0, i64 3), align 4
+// CHECK-NEXT: ret i32 [[TMP0]]
+//
+int f() { return a[3].x; }
More information about the cfe-commits
mailing list