From 0035283acf0f33d8b17b70b17a55df858073e422 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 20 Nov 2014 03:37:32 +0000 Subject: [PATCH] Preserve numeric literal suffixes during type canonicalization. Patch by Pierre Gousseau! Test cases altered significantly by me. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222404 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/StmtProfile.cpp | 2 ++ test/CodeGenCXX/mangle-literal-suffix.cpp | 17 +++++++++++++++++ test/SemaTemplate/canonical-expr-type.cpp | 8 ++++++++ 3 files changed, 27 insertions(+) create mode 100644 test/CodeGenCXX/mangle-literal-suffix.cpp diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index 647b643486..d1f25d63b3 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -501,6 +501,7 @@ void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) { void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) { VisitExpr(S); S->getValue().Profile(ID); + ID.AddInteger(S->getType()->castAs()->getKind()); } void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) { @@ -513,6 +514,7 @@ void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) { VisitExpr(S); S->getValue().Profile(ID); ID.AddBoolean(S->isExact()); + ID.AddInteger(S->getType()->castAs()->getKind()); } void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) { diff --git a/test/CodeGenCXX/mangle-literal-suffix.cpp b/test/CodeGenCXX/mangle-literal-suffix.cpp new file mode 100644 index 0000000000..7a3e8ad3ba --- /dev/null +++ b/test/CodeGenCXX/mangle-literal-suffix.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -triple mips-none-none -emit-llvm -o - %s | FileCheck %s + +template void g3(char (&buffer)[sizeof(T() + 5.0)]) {} +template void g3(char (&)[sizeof(double)]); +// CHECK: _Z2g3IdEvRAszplcvT__ELd4014000000000000E_c + +template void g4(char (&buffer)[sizeof(T() + 5.0L)]) {} +template void g4(char (&)[sizeof(long double)]); +// CHECK: _Z2g4IeEvRAszplcvT__ELe4014000000000000E_c + +template void g5(char (&buffer)[sizeof(T() + 5)]) {} +template void g5(char (&)[sizeof(int)]); +// CHECK: _Z2g5IiEvRAszplcvT__ELi5E_c + +template void g6(char (&buffer)[sizeof(T() + 5L)]) {} +template void g6(char (&)[sizeof(long int)]); +// CHECK: _Z2g6IlEvRAszplcvT__ELl5E_c diff --git a/test/SemaTemplate/canonical-expr-type.cpp b/test/SemaTemplate/canonical-expr-type.cpp index 4770c4fa3e..f8d7d7ec1a 100644 --- a/test/SemaTemplate/canonical-expr-type.cpp +++ b/test/SemaTemplate/canonical-expr-type.cpp @@ -47,3 +47,11 @@ struct X2 { void f0(type2); void f0(type3); // expected-error{{redeclared}} }; + +// Test canonicalization doesn't conflate different literal suffixes. +template void literal_suffix(int (&)[sizeof(T() + 0)]) {} +template void literal_suffix(int (&)[sizeof(T() + 0L)]) {} +template void literal_suffix(int (&)[sizeof(T() + 0LL)]) {} +template void literal_suffix(int (&)[sizeof(T() + 0.f)]) {} +template void literal_suffix(int (&)[sizeof(T() + 0.)]) {} +template void literal_suffix(int (&)[sizeof(T() + 0.l)]) {} -- 2.40.0