aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/expand/rust-macro-builtins-asm.cc
diff options
context:
space:
mode:
authorjjasmine <tanghocle456@gmail.com>2024-05-22 02:00:09 -0700
committerCohenArthur <arthur.cohen@embecosm.com>2024-06-13 15:31:07 +0000
commita4cbd38f06c2d4f6859b7bda3086cd62f9e0dfca (patch)
treed118bcbdf1fc21e8e9f08558d0307fd078f0938d /gcc/rust/expand/rust-macro-builtins-asm.cc
parented17ab77c334c0351f92805695640d9a57e2bbd4 (diff)
downloadgcc-a4cbd38f06c2d4f6859b7bda3086cd62f9e0dfca.zip
gcc-a4cbd38f06c2d4f6859b7bda3086cd62f9e0dfca.tar.gz
gcc-a4cbd38f06c2d4f6859b7bda3086cd62f9e0dfca.tar.bz2
Add checks for duplicate options in inline asm
gcc/rust/ChangeLog: * expand/rust-macro-builtins-asm.cc (check_and_set): Add checks for duplicate options in inline asm (parse_options): likewise. gcc/testsuite/ChangeLog: * rust/compile/inline_asm_illegal_options.rs: New test.
Diffstat (limited to 'gcc/rust/expand/rust-macro-builtins-asm.cc')
-rw-r--r--gcc/rust/expand/rust-macro-builtins-asm.cc35
1 files changed, 25 insertions, 10 deletions
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc b/gcc/rust/expand/rust-macro-builtins-asm.cc
index a86d58e..185bf38 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -19,6 +19,17 @@
#include "rust-macro-builtins-asm.h"
namespace Rust {
+std::map<AST::InlineAsmOptions, std::string> InlineAsmOptionsMap{
+ {AST::InlineAsmOptions::PURE, "pure"},
+ {AST::InlineAsmOptions::NOMEM, "nomem"},
+ {AST::InlineAsmOptions::READONLY, "readonly"},
+ {AST::InlineAsmOptions::PRESERVES_FLAGS, "preserves_flags"},
+ {AST::InlineAsmOptions::NORETURN, "noreturn"},
+ {AST::InlineAsmOptions::NOSTACK, "nostack"},
+ {AST::InlineAsmOptions::MAY_UNWIND, "may_unwind"},
+ {AST::InlineAsmOptions::ATT_SYNTAX, "att_syntax"},
+ {AST::InlineAsmOptions::RAW, "raw"},
+};
int
parseDirSpec (Parser<MacroInvocLexer> &parser, TokenId last_token_id)
@@ -115,13 +126,15 @@ parse_clobber_abi (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
}
void
-check_and_set (Parser<MacroInvocLexer> &p, AST::InlineAsm &inlineAsm,
+check_and_set (Parser<MacroInvocLexer> &parser, AST::InlineAsm &inlineAsm,
AST::InlineAsmOptions option)
{
- if (inlineAsm.options.count (option) == 1)
+ if (inlineAsm.options.count (option) != 0)
{
// TODO: report an error of duplication
-
+ rust_error_at (parser.peek_current_token ()->get_locus (),
+ "the `%s` option was already provided",
+ InlineAsmOptionsMap[option].c_str ());
return;
}
else
@@ -189,20 +202,22 @@ parse_options (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
rust_error_at (token->get_locus (),
"Unexpected token encountered in parse_options");
}
- if (!parser.skip_token (RIGHT_PAREN))
+ if (parser.skip_token (RIGHT_PAREN))
{
break;
}
- if (!parser.skip_token (COMMA))
+ // Parse comma as optional
+ if (parser.skip_token (COMMA))
{
- // TODO: If the skip of comma is unsuccessful, which should be
- // illegal, pleaes emit the correct error.
- std::cout << "Illegal comma" << std::endl;
+ continue;
+ }
+ else
+ {
+ std::cout << "Sum wrong here, check it out" << std::endl;
+ token = parser.peek_current_token ();
return -1;
}
-
- token = parser.peek_current_token ();
}
// TODO: Per rust asm.rs regarding options_spans