@@ -207,11 +207,17 @@ static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
207207 }
208208 if (Done) break ;
209209
210+ bool HasCurlyBraces = false ;
211+ if (*LastEmitted == ' {' ) { // ${variable}
212+ ++LastEmitted; // Consume '{' character.
213+ HasCurlyBraces = true ;
214+ }
215+
210216 // If we have ${:foo}, then this is not a real operand reference, it is a
211217 // "magic" string reference, just like in .td files. Arrange to call
212218 // PrintSpecial.
213- if (LastEmitted[ 0 ] == ' { ' && LastEmitted[1 ] == ' :' ) {
214- LastEmitted += 2 ;
219+ if (HasCurlyBraces && LastEmitted[0 ] == ' :' ) {
220+ ++LastEmitted ;
215221 const char *StrStart = LastEmitted;
216222 const char *StrEnd = strchr (StrStart, ' }' );
217223 if (!StrEnd)
@@ -238,6 +244,27 @@ static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
238244 report_fatal_error (" Invalid $ operand number in inline asm string: '" +
239245 Twine (AsmStr) + " '" );
240246
247+ char Modifier[2 ] = { 0 , 0 };
248+
249+ if (HasCurlyBraces) {
250+ // If we have curly braces, check for a modifier character. This
251+ // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
252+ if (*LastEmitted == ' :' ) {
253+ ++LastEmitted; // Consume ':' character.
254+ if (*LastEmitted == 0 )
255+ report_fatal_error (" Bad ${:} expression in inline asm string: '" +
256+ Twine (AsmStr) + " '" );
257+
258+ Modifier[0 ] = *LastEmitted;
259+ ++LastEmitted; // Consume modifier character.
260+ }
261+
262+ if (*LastEmitted != ' }' )
263+ report_fatal_error (" Bad ${} expression in inline asm string: '" +
264+ Twine (AsmStr) + " '" );
265+ ++LastEmitted; // Consume '}' character.
266+ }
267+
241268 // Okay, we finally have a value number. Ask the target to print this
242269 // operand!
243270 unsigned OpNo = InlineAsm::MIOp_FirstOperand;
@@ -262,9 +289,11 @@ static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
262289 ++OpNo; // Skip over the ID number.
263290
264291 if (InlineAsm::isMemKind (OpFlags)) {
265- Error = AP->PrintAsmMemoryOperand (MI, OpNo, /* Modifier*/ nullptr , OS);
292+ Error = AP->PrintAsmMemoryOperand (
293+ MI, OpNo, Modifier[0 ] ? Modifier : nullptr , OS);
266294 } else {
267- Error = AP->PrintAsmOperand (MI, OpNo, /* Modifier*/ nullptr , OS);
295+ Error = AP->PrintAsmOperand (MI, OpNo,
296+ Modifier[0 ] ? Modifier : nullptr , OS);
268297 }
269298 }
270299 if (Error) {
0 commit comments