[Lexer] Fix invalid suffix diagnostic for fixed-point literals
Committing on behalf of nagart, who authored this patch. Differential Revision: https://reviews.llvm.org/D80412
This commit is contained in:
parent
5e007fe998
commit
ef37444058
|
@ -175,7 +175,7 @@ def ext_unknown_escape : ExtWarn<"unknown escape sequence '\\%0'">,
|
||||||
def err_invalid_digit : Error<
|
def err_invalid_digit : Error<
|
||||||
"invalid digit '%0' in %select{decimal|octal|binary}1 constant">;
|
"invalid digit '%0' in %select{decimal|octal|binary}1 constant">;
|
||||||
def err_invalid_suffix_constant : Error<
|
def err_invalid_suffix_constant : Error<
|
||||||
"invalid suffix '%0' on %select{integer|floating}1 constant">;
|
"invalid suffix '%0' on %select{integer|floating|fixed-point}1 constant">;
|
||||||
def warn_cxx11_compat_digit_separator : Warning<
|
def warn_cxx11_compat_digit_separator : Warning<
|
||||||
"digit separators are incompatible with C++ standards before C++14">,
|
"digit separators are incompatible with C++ standards before C++14">,
|
||||||
InGroup<CXXPre14Compat>, DefaultIgnore;
|
InGroup<CXXPre14Compat>, DefaultIgnore;
|
||||||
|
|
|
@ -71,7 +71,9 @@ public:
|
||||||
bool isFract : 1; // 1.0hr/r/lr/uhr/ur/ulr
|
bool isFract : 1; // 1.0hr/r/lr/uhr/ur/ulr
|
||||||
bool isAccum : 1; // 1.0hk/k/lk/uhk/uk/ulk
|
bool isAccum : 1; // 1.0hk/k/lk/uhk/uk/ulk
|
||||||
|
|
||||||
bool isFixedPointLiteral() const { return saw_fixed_point_suffix; }
|
bool isFixedPointLiteral() const {
|
||||||
|
return (saw_period || saw_exponent) && saw_fixed_point_suffix;
|
||||||
|
}
|
||||||
|
|
||||||
bool isIntegerLiteral() const {
|
bool isIntegerLiteral() const {
|
||||||
return !saw_period && !saw_exponent && !isFixedPointLiteral();
|
return !saw_period && !saw_exponent && !isFixedPointLiteral();
|
||||||
|
|
|
@ -583,6 +583,7 @@ NumericLiteralParser::NumericLiteralParser(StringRef TokSpelling,
|
||||||
|
|
||||||
// Parse the suffix. At this point we can classify whether we have an FP or
|
// Parse the suffix. At this point we can classify whether we have an FP or
|
||||||
// integer constant.
|
// integer constant.
|
||||||
|
bool isFixedPointConstant = isFixedPointLiteral();
|
||||||
bool isFPConstant = isFloatingLiteral();
|
bool isFPConstant = isFloatingLiteral();
|
||||||
|
|
||||||
// Loop over all of the characters of the suffix. If we see something bad,
|
// Loop over all of the characters of the suffix. If we see something bad,
|
||||||
|
@ -737,7 +738,8 @@ NumericLiteralParser::NumericLiteralParser(StringRef TokSpelling,
|
||||||
// Report an error if there are any.
|
// Report an error if there are any.
|
||||||
PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, SuffixBegin - ThisTokBegin),
|
PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, SuffixBegin - ThisTokBegin),
|
||||||
diag::err_invalid_suffix_constant)
|
diag::err_invalid_suffix_constant)
|
||||||
<< StringRef(SuffixBegin, ThisTokEnd - SuffixBegin) << isFPConstant;
|
<< StringRef(SuffixBegin, ThisTokEnd - SuffixBegin)
|
||||||
|
<< (isFixedPointConstant ? 2 : isFPConstant);
|
||||||
hadError = true;
|
hadError = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,15 +137,15 @@ _Sat longfract_t td_sat_long_fract; // expected-error{{'_Sat' specifier
|
||||||
_Sat longaccum_t td_sat_long_accum; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
|
_Sat longaccum_t td_sat_long_accum; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
|
||||||
|
|
||||||
/* Bad suffixes */
|
/* Bad suffixes */
|
||||||
_Accum fk = 1.0fk; // expected-error{{invalid suffix 'fk' on integer constant}}
|
_Accum fk = 1.0fk; // expected-error{{invalid suffix 'fk' on fixed-point constant}}
|
||||||
_Accum kk = 1.0kk; // expected-error{{invalid suffix 'kk' on integer constant}}
|
_Accum kk = 1.0kk; // expected-error{{invalid suffix 'kk' on fixed-point constant}}
|
||||||
_Accum rk = 1.0rk; // expected-error{{invalid suffix 'rk' on integer constant}}
|
_Accum rk = 1.0rk; // expected-error{{invalid suffix 'rk' on fixed-point constant}}
|
||||||
_Accum rk = 1.0rr; // expected-error{{invalid suffix 'rr' on integer constant}}
|
_Accum rk = 1.0rr; // expected-error{{invalid suffix 'rr' on fixed-point constant}}
|
||||||
_Accum qk = 1.0qr; // expected-error{{invalid suffix 'qr' on integer constant}}
|
_Accum qk = 1.0qr; // expected-error{{invalid suffix 'qr' on fixed-point constant}}
|
||||||
|
|
||||||
/* Using wrong exponent notation */
|
/* Using wrong exponent notation */
|
||||||
_Accum dec_with_hex_exp1 = 0.1p10k; // expected-error{{invalid suffix 'p10k' on integer constant}}
|
_Accum dec_with_hex_exp1 = 0.1p10k; // expected-error{{invalid suffix 'p10k' on fixed-point constant}}
|
||||||
_Accum dec_with_hex_exp2 = 0.1P10k; // expected-error{{invalid suffix 'P10k' on integer constant}}
|
_Accum dec_with_hex_exp2 = 0.1P10k; // expected-error{{invalid suffix 'P10k' on fixed-point constant}}
|
||||||
_Accum hex_with_dex_exp1 = 0x0.1e10k; // expected-error{{hexadecimal floating constant requires an exponent}}
|
_Accum hex_with_dex_exp1 = 0x0.1e10k; // expected-error{{hexadecimal floating constant requires an exponent}}
|
||||||
_Accum hex_with_dex_exp2 = 0x0.1E10k; // expected-error{{hexadecimal floating constant requires an exponent}}
|
_Accum hex_with_dex_exp2 = 0x0.1E10k; // expected-error{{hexadecimal floating constant requires an exponent}}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue