summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorLeonard Chan <leonardchan@google.com>2018-07-17 14:58:49 +0000
committerLeonard Chan <leonardchan@google.com>2018-07-17 14:58:49 +0000
commite5597ad9f3132bf9f4d9baddb513d5c704f28c2c (patch)
tree1d2cb457aaf1dd5127e67b0c501e2feeeeda0c3a /clang/lib
parentf10e4798b4d9f5d52da9c004341b7c98727638f8 (diff)
downloadbcm5719-llvm-e5597ad9f3132bf9f4d9baddb513d5c704f28c2c.tar.gz
bcm5719-llvm-e5597ad9f3132bf9f4d9baddb513d5c704f28c2c.zip
[Fixed Point Arithmetic] Fix for bug where integer literals could be treated as fixed point literals
This addresses a bug brought up in https://bugs.llvm.org/show_bug.cgi?id=38161 where integer literals could be treated as fixed point types and throw errors related to fixed point types when the 'k' or 'r' suffix used. The fix also addresses the second issue brought up with the assertion by not treating integers as fixed point types in the first place. Integers that have suffixes 'k' and 'r' now throw the error `invalid suffix 'k/r' on integer constant`. A few more tests were also added to ensure that fixed point types, and any errors/warnings related to them, are limited to C for now. Prior discussion also at https://reviews.llvm.org/D46915. Differential Revision: https://reviews.llvm.org/D49327 llvm-svn: 337289
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Lex/LiteralSupport.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index c1be3b2a97e..e695b2ba376 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -572,10 +572,12 @@ NumericLiteralParser::NumericLiteralParser(StringRef TokSpelling,
checkSeparator(TokLoc, s, CSK_AfterDigits);
// Initial scan to lookahead for fixed point suffix.
- for (const char *c = s; c != ThisTokEnd; ++c) {
- if (*c == 'r' || *c == 'k' || *c == 'R' || *c == 'K') {
- saw_fixed_point_suffix = true;
- break;
+ if (PP.getLangOpts().FixedPoint) {
+ for (const char *c = s; c != ThisTokEnd; ++c) {
+ if (*c == 'r' || *c == 'k' || *c == 'R' || *c == 'K') {
+ saw_fixed_point_suffix = true;
+ break;
+ }
}
}
@@ -589,12 +591,16 @@ NumericLiteralParser::NumericLiteralParser(StringRef TokSpelling,
switch (*s) {
case 'R':
case 'r':
+ if (!PP.getLangOpts().FixedPoint) break;
if (isFract || isAccum) break;
+ if (!(saw_period || saw_exponent)) break;
isFract = true;
continue;
case 'K':
case 'k':
+ if (!PP.getLangOpts().FixedPoint) break;
if (isFract || isAccum) break;
+ if (!(saw_period || saw_exponent)) break;
isAccum = true;
continue;
case 'h': // FP Suffix for "half".
@@ -734,7 +740,6 @@ NumericLiteralParser::NumericLiteralParser(StringRef TokSpelling,
if (!hadError && saw_fixed_point_suffix) {
assert(isFract || isAccum);
- //assert(radix == 16 || radix == 10);
}
}
OpenPOWER on IntegriCloud