@@ -130,6 +130,11 @@ Error FileCheckPattern::parseNumericVariableDefinition(
130
130
return FileCheckErrorDiagnostic::get (
131
131
SM, Name, " string variable with name '" + Name + " ' already exists" );
132
132
133
+ Expr = Expr.ltrim (SpaceChars);
134
+ if (!Expr.empty ())
135
+ return FileCheckErrorDiagnostic::get (
136
+ SM, Expr, " unexpected characters after numeric variable name" );
137
+
133
138
return Error::success ();
134
139
}
135
140
@@ -229,27 +234,21 @@ Expected<FileCheckExpression *> FileCheckPattern::parseNumericSubstitutionBlock(
229
234
size_t DefEnd = Expr.find (' :' );
230
235
if (DefEnd != StringRef::npos) {
231
236
StringRef DefExpr = Expr.substr (0 , DefEnd);
232
- StringRef UseExpr = Expr = Expr .substr (DefEnd + 1 );
237
+ StringRef UseExpr = Expr.substr (DefEnd + 1 );
233
238
234
- DefExpr = DefExpr.ltrim (SpaceChars);
235
- StringRef Name;
236
- Error ErrorDiagnostic =
237
- parseNumericVariableDefinition (DefExpr, Name, Context, SM);
238
- if (ErrorDiagnostic)
239
- return std::move (ErrorDiagnostic);
240
-
241
- DefinedNumericVariable =
242
- Context->makeNumericVariable (this ->LineNumber , Name);
243
-
244
- DefExpr = DefExpr.ltrim (SpaceChars);
245
- if (!DefExpr.empty ())
246
- return FileCheckErrorDiagnostic::get (
247
- SM, DefExpr, " invalid numeric variable definition" );
248
239
UseExpr = UseExpr.ltrim (SpaceChars);
249
240
if (!UseExpr.empty ())
250
241
return FileCheckErrorDiagnostic::get (
251
242
SM, UseExpr,
252
243
" unexpected string after variable definition: '" + UseExpr + " '" );
244
+
245
+ DefExpr = DefExpr.ltrim (SpaceChars);
246
+ StringRef Name;
247
+ Error Err = parseNumericVariableDefinition (DefExpr, Name, Context, SM);
248
+ if (Err)
249
+ return std::move (Err);
250
+ DefinedNumericVariable = Context->makeNumericVariable (LineNumber, Name);
251
+
253
252
return Context->makeExpression (add, nullptr , 0 );
254
253
}
255
254
@@ -1735,32 +1734,12 @@ Error FileCheckPatternContext::defineCmdlineVariables(
1735
1734
if (CmdlineDef[0 ] == ' #' ) {
1736
1735
StringRef CmdlineName = CmdlineDef.substr (1 , EqIdx - 1 );
1737
1736
StringRef VarName;
1738
- SMLoc CmdlineNameLoc = SMLoc::getFromPointer (CmdlineName.data ());
1739
1737
Error ErrorDiagnostic = FileCheckPattern::parseNumericVariableDefinition (
1740
1738
CmdlineName, VarName, this , SM);
1741
1739
if (ErrorDiagnostic) {
1742
1740
Errs = joinErrors (std::move (Errs), std::move (ErrorDiagnostic));
1743
1741
continue ;
1744
1742
}
1745
- // Check that CmdlineName is only composed of the parsed numeric
1746
- // variable. This catches cases like "FOO+2" in a "FOO+2=10" definition.
1747
- if (!CmdlineName.empty ()) {
1748
- Errs = joinErrors (std::move (Errs),
1749
- FileCheckErrorDiagnostic::get (
1750
- SM, CmdlineNameLoc, " invalid variable name" ));
1751
- continue ;
1752
- }
1753
-
1754
- // Detect collisions between string and numeric variables when the latter
1755
- // is created later than the former.
1756
- if (DefinedVariableTable.find (VarName) != DefinedVariableTable.end ()) {
1757
- Errs = joinErrors (
1758
- std::move (Errs),
1759
- FileCheckErrorDiagnostic::get (SM, VarName,
1760
- " string variable with name '" +
1761
- VarName + " ' already exists" ));
1762
- continue ;
1763
- }
1764
1743
1765
1744
StringRef CmdlineVal = CmdlineDef.substr (EqIdx + 1 );
1766
1745
uint64_t Val;
0 commit comments