r222404 - Preserve numeric literal suffixes during type canonicalization.

Richard Smith richard-llvm at metafoo.co.uk
Wed Nov 19 19:37:33 PST 2014


Author: rsmith
Date: Wed Nov 19 21:37:32 2014
New Revision: 222404

URL: http://llvm.org/viewvc/llvm-project?rev=222404&view=rev
Log:
Preserve numeric literal suffixes during type canonicalization.
Patch by Pierre Gousseau! Test cases altered significantly by me.

Added:
    cfe/trunk/test/CodeGenCXX/mangle-literal-suffix.cpp
Modified:
    cfe/trunk/lib/AST/StmtProfile.cpp
    cfe/trunk/test/SemaTemplate/canonical-expr-type.cpp

Modified: cfe/trunk/lib/AST/StmtProfile.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtProfile.cpp?rev=222404&r1=222403&r2=222404&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtProfile.cpp (original)
+++ cfe/trunk/lib/AST/StmtProfile.cpp Wed Nov 19 21:37:32 2014
@@ -501,6 +501,7 @@ void StmtProfiler::VisitPredefinedExpr(c
 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
   VisitExpr(S);
   S->getValue().Profile(ID);
+  ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
 }
 
 void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
@@ -513,6 +514,7 @@ void StmtProfiler::VisitFloatingLiteral(
   VisitExpr(S);
   S->getValue().Profile(ID);
   ID.AddBoolean(S->isExact());
+  ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
 }
 
 void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {

Added: cfe/trunk/test/CodeGenCXX/mangle-literal-suffix.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-literal-suffix.cpp?rev=222404&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-literal-suffix.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/mangle-literal-suffix.cpp Wed Nov 19 21:37:32 2014
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple mips-none-none -emit-llvm -o - %s | FileCheck %s
+
+template <class T> void g3(char (&buffer)[sizeof(T() + 5.0)]) {}
+template void g3(char (&)[sizeof(double)]);
+// CHECK: _Z2g3IdEvRAszplcvT__ELd4014000000000000E_c
+
+template <class T> void g4(char (&buffer)[sizeof(T() + 5.0L)]) {}
+template void g4(char (&)[sizeof(long double)]);
+// CHECK: _Z2g4IeEvRAszplcvT__ELe4014000000000000E_c
+
+template <class T> void g5(char (&buffer)[sizeof(T() + 5)]) {}
+template void g5(char (&)[sizeof(int)]);
+// CHECK: _Z2g5IiEvRAszplcvT__ELi5E_c
+
+template <class T> void g6(char (&buffer)[sizeof(T() + 5L)]) {}
+template void g6(char (&)[sizeof(long int)]);
+// CHECK: _Z2g6IlEvRAszplcvT__ELl5E_c

Modified: cfe/trunk/test/SemaTemplate/canonical-expr-type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/canonical-expr-type.cpp?rev=222404&r1=222403&r2=222404&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/canonical-expr-type.cpp (original)
+++ cfe/trunk/test/SemaTemplate/canonical-expr-type.cpp Wed Nov 19 21:37:32 2014
@@ -47,3 +47,11 @@ struct X2 {
   void f0(type2);
   void f0(type3); // expected-error{{redeclared}}
 };
+
+// Test canonicalization doesn't conflate different literal suffixes.
+template<typename T> void literal_suffix(int (&)[sizeof(T() + 0)]) {}
+template<typename T> void literal_suffix(int (&)[sizeof(T() + 0L)]) {}
+template<typename T> void literal_suffix(int (&)[sizeof(T() + 0LL)]) {}
+template<typename T> void literal_suffix(int (&)[sizeof(T() + 0.f)]) {}
+template<typename T> void literal_suffix(int (&)[sizeof(T() + 0.)]) {}
+template<typename T> void literal_suffix(int (&)[sizeof(T() + 0.l)]) {}





More information about the cfe-commits mailing list