[PATCH] Creating a printing policy for "half"
Yunzhong Gao
Yunzhong_Gao at playstation.sony.com
Tue Mar 4 17:37:57 PST 2014
ygao added you to the CC list for the revision "Creating a printing policy for "half"".
Hi,
Since "half" is an OpenCL keyword and clang accepts __fp16 as an extension for other languages,
error messages and metadata (and hence debug info) should refer to the half-precision floating point
as "__fp16" instead of "half" when compiling for non-OpenCL languages. This patch creates a new
printing policy for half in a similar manner to what is done for bool and wchar_t.
Can someone take a look whether this seems reasonable?
- Gao
http://llvm-reviews.chandlerc.com/D2952
Files:
include/clang/AST/PrettyPrinter.h
include/clang/Basic/LangOptions.def
lib/AST/Type.cpp
lib/Frontend/CompilerInvocation.cpp
test/CXX/expr/expr.const/p2-0x.cpp
test/Sema/variadic-promotion.c
Index: include/clang/AST/PrettyPrinter.h
===================================================================
--- include/clang/AST/PrettyPrinter.h
+++ include/clang/AST/PrettyPrinter.h
@@ -41,7 +41,7 @@
ConstantArraySizeAsWritten(false), AnonymousTagLocations(true),
SuppressStrongLifetime(false), SuppressLifetimeQualifiers(false),
Bool(LO.Bool), TerseOutput(false), PolishForDeclaration(false),
- MSWChar(LO.MicrosoftExt && !LO.WChar),
+ Half(LO.Half), MSWChar(LO.MicrosoftExt && !LO.WChar),
IncludeNewlines(true) { }
/// \brief What language we're printing.
@@ -153,6 +153,10 @@
///
unsigned PolishForDeclaration : 1;
+ /// \brief When true, print the half-precision floating-point type as 'half'
+ /// instead of '__fp16'
+ unsigned Half : 1;
+
/// \brief When true, print the built-in wchar_t type as __wchar_t. For use in
/// Microsoft mode when wchar_t is not available.
unsigned MSWChar : 1;
Index: include/clang/Basic/LangOptions.def
===================================================================
--- include/clang/Basic/LangOptions.def
+++ include/clang/Basic/LangOptions.def
@@ -61,6 +61,7 @@
LANGOPT(Trigraphs , 1, 0,"trigraphs")
LANGOPT(LineComment , 1, 0, "'//' comments")
LANGOPT(Bool , 1, 0, "bool, true, and false keywords")
+LANGOPT(Half , 1, 0, "half keyword")
LANGOPT(WChar , 1, CPlusPlus, "wchar_t keyword")
BENIGN_LANGOPT(DollarIdents , 1, 1, "'$' in identifiers")
BENIGN_LANGOPT(AsmPreprocessor, 1, 0, "preprocessor in asm mode")
Index: lib/AST/Type.cpp
===================================================================
--- lib/AST/Type.cpp
+++ lib/AST/Type.cpp
@@ -1523,7 +1523,7 @@
case ULong: return "unsigned long";
case ULongLong: return "unsigned long long";
case UInt128: return "unsigned __int128";
- case Half: return "half";
+ case Half: return Policy.Half ? "half" : "__fp16";
case Float: return "float";
case Double: return "double";
case LongDouble: return "long double";
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1112,6 +1114,9 @@
// OpenCL and C++ both have bool, true, false keywords.
Opts.Bool = Opts.OpenCL || Opts.CPlusPlus;
+ // OpenCL has half keyword
+ Opts.Half = Opts.OpenCL;
+
// C++ has wchar_t keyword.
Opts.WChar = Opts.CPlusPlus;
Index: test/CXX/expr/expr.const/p2-0x.cpp
===================================================================
--- test/CXX/expr/expr.const/p2-0x.cpp
+++ test/CXX/expr/expr.const/p2-0x.cpp
@@ -138,7 +138,7 @@
case (int)(unsigned)(long long)4.4e9: // ok
case (int)(float)1e300: // expected-error {{constant expression}} expected-note {{value 1.0E+300 is outside the range of representable values of type 'float'}} expected-error {{duplicate case value '2147483647'}} expected-note {{previous case defined here}}
case (int)((float)1e37 / 1e30): // ok
- case (int)(__fp16)65536: // expected-error {{constant expression}} expected-note {{value 65536 is outside the range of representable values of type 'half'}} expected-error {{duplicate case value '2147483647'}}
+ case (int)(__fp16)65536: // expected-error {{constant expression}} expected-note {{value 65536 is outside the range of representable values of type '__fp16'}} expected-error {{duplicate case value '2147483647'}}
break;
}
}
Index: test/Sema/variadic-promotion.c
===================================================================
--- test/Sema/variadic-promotion.c
+++ test/Sema/variadic-promotion.c
@@ -6,7 +6,7 @@
variadic(3, *f16, f32, f64);
// CHECK: ImplicitCastExpr {{.*}} 'double' <FloatingCast>
-// CHECK-NEXT: 'half'
+// CHECK-NEXT: '__fp16'
// CHECK: ImplicitCastExpr {{.*}} 'double' <FloatingCast>
// CHECK-NEXT: 'float'
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2952.1.patch
Type: text/x-patch
Size: 4028 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140304/5494175b/attachment.bin>
More information about the cfe-commits
mailing list