diff options
author | Chris Mihelich <cmihelic@google.com> | 2024-06-06 13:00:55 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-06-06 13:01:45 -0700 |
commit | 0cd50e6ee37f1bd8be8dd716694470a7f20b6a59 (patch) | |
tree | 35ad3a5e2a53d05a129e0d76d9db082a298a6ff3 /absl/debugging/internal/demangle_test.cc | |
parent | 586a541d2bd9f66f7a7115338f3a2402ae5c46b6 (diff) |
Demangle dependent GNU vector extension types, Dv <expression> _ <type>.
PiperOrigin-RevId: 640993627
Change-Id: I84073099907a3634eca4b12cd2e633908465907a
Diffstat (limited to 'absl/debugging/internal/demangle_test.cc')
-rw-r--r-- | absl/debugging/internal/demangle_test.cc | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/absl/debugging/internal/demangle_test.cc b/absl/debugging/internal/demangle_test.cc index 0b12234f..1d108c8b 100644 --- a/absl/debugging/internal/demangle_test.cc +++ b/absl/debugging/internal/demangle_test.cc @@ -671,6 +671,66 @@ TEST(Demangle, AbiTags) { EXPECT_STREQ("C[abi:bar][abi:foo]()", tmp); } +TEST(Demangle, SimpleGnuVectorSize) { + char tmp[80]; + + // Source: + // + // #define VECTOR(size) __attribute__((vector_size(size))) + // void f(int x VECTOR(32)) {} + // + // The attribute's size is a number of bytes. The compiler verifies that this + // value corresponds to a whole number of elements and emits the number of + // elements as a <number> in the mangling. With sizeof(int) == 4, that yields + // 32/4 = 8. + // + // LLVM demangling: + // + // f(int vector[8]) + EXPECT_TRUE(Demangle("_Z1fDv8_i", tmp, sizeof(tmp))); + EXPECT_STREQ("f()", tmp); +} + +TEST(Demangle, GnuVectorSizeIsATemplateParameter) { + char tmp[80]; + + // Source: + // + // #define VECTOR(size) __attribute__((vector_size(size))) + // template <int n> void f(int x VECTOR(n)) {} + // template void f<32>(int x VECTOR(32)); + // + // LLVM demangling: + // + // void f<32>(int vector[32]) + // + // Because the size was dependent on a template parameter, it was encoded + // using the general expression encoding. Nothing in the mangling says how + // big the element type is, so the demangler is unable to show the element + // count 8 instead of the byte count 32. Arguably it would have been better + // to make the narrow production encode the byte count, so that nondependent + // and dependent versions of a 32-byte vector would both come out as + // vector[32]. + EXPECT_TRUE(Demangle("_Z1fILi32EEvDvT__i", tmp, sizeof(tmp))); + EXPECT_STREQ("f<>()", tmp); +} + +TEST(Demangle, GnuVectorSizeIsADependentOperatorExpression) { + char tmp[80]; + + // Source: + // + // #define VECTOR(size) __attribute__((vector_size(size))) + // template <int n> void f(int x VECTOR(2 * n)) {} + // template void f<32>(int x VECTOR(2 * 32)); + // + // LLVM demangling: + // + // void f<32>(int vector[2 * 32]) + EXPECT_TRUE(Demangle("_Z1fILi32EEvDvmlLi2ET__i", tmp, sizeof(tmp))); + EXPECT_STREQ("f<>()", tmp); +} + TEST(Demangle, EnableIfAttributeOnGlobalFunction) { char tmp[80]; |