summaryrefslogtreecommitdiffstats
path: root/clang/test/CodeGen/mangle-ms-string-literals.c
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2018-07-06 06:54:16 +0000
committerHans Wennborg <hans@hanshq.net>2018-07-06 06:54:16 +0000
commit7525edc89078f138c9dad6bdb3c5eed31f65c017 (patch)
tree916c2a8eed1c856371d8aff2e82f34be541f887b /clang/test/CodeGen/mangle-ms-string-literals.c
parent78c46bdf52b19b5a513e683c08178f01439c7fc5 (diff)
downloadbcm5719-llvm-7525edc89078f138c9dad6bdb3c5eed31f65c017.tar.gz
bcm5719-llvm-7525edc89078f138c9dad6bdb3c5eed31f65c017.zip
[ms] Fix mangling of string literals used to initialize arrays larger or smaller than the literal
A Chromium developer reported a bug which turned out to be a mangling collision between these two literals: char s[] = "foo"; char t[32] = "foo"; They may look the same, but for the initialization of t we will (under some circumstances) use a literal that's extended with zeros, and both the length and those zeros should be accounted for by the mangling. This actually makes the mangling code simpler: where it previously had special logic for null terminators, which are not part of the StringLiteral, that is now covered by the general algorithm. (The problem was reported at https://crbug.com/857442) Differential Revision: https://reviews.llvm.org/D48928 llvm-svn: 336415
Diffstat (limited to 'clang/test/CodeGen/mangle-ms-string-literals.c')
-rw-r--r--clang/test/CodeGen/mangle-ms-string-literals.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/test/CodeGen/mangle-ms-string-literals.c b/clang/test/CodeGen/mangle-ms-string-literals.c
new file mode 100644
index 00000000000..41dd78c1fa7
--- /dev/null
+++ b/clang/test/CodeGen/mangle-ms-string-literals.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -x c -emit-llvm %s -o - -triple=i386-pc-win32 | FileCheck %s
+// RUN: %clang_cc1 -x c -emit-llvm %s -o - -triple=x86_64-pc-win32 | FileCheck %s
+
+void crbug857442(int x) {
+ // Make sure to handle truncated or padded literals. The truncation is only valid in C.
+ struct {int x; char s[2]; } truncatedAscii = {x, "hello"};
+ // CHECK: "??_C@_01CONKJJHI@he@"
+ struct {int x; char s[16]; } paddedAscii = {x, "hello"};
+ // CHECK: "??_C@_0BA@EAAINDNC@hello?$AA?$AA?$AA?$AA?$AA?$AA?$AA?$AA?$AA?$AA?$AA@"
+}
OpenPOWER on IntegriCloud