aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/evaluate.c
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-01-17 22:58:01 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-09-27 02:17:34 +0200
commit7aeb06b4bff797da4ea85a18738a2fd1f660d744 (patch)
tree6955efba6e8474607407b1df654911f1216555c7 /evaluate.c
parent62308ab6a6025f8df926b8af009f68fbebe040b6 (diff)
downloadsparse-7aeb06b4bff797da4ea85a18738a2fd1f660d744.tar.gz
asm: check earlier that body & constraints are strings
The syntax of extended ASM statements requires that the bodies & constraints are given via a literal string. However, at parsing time more general expressions are accepted and it's checked only at evaluation time if these are effectively string literals. This has at least two drawbacks: *) evaluate_asm_statement() is slightly more complicated than needed, mixing these checks with the real evaluation code *) in case of error, the diagnostic is issued later than other syntaxic warnings. Fix this by checking at parse-time that ASM bodies & constraints are string literals and not some arbitrary expressions. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'evaluate.c')
-rw-r--r--evaluate.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/evaluate.c b/evaluate.c
index 70d76523..634da4b9 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -3523,20 +3523,15 @@ static void evaluate_asm_statement(struct statement *stmt)
struct symbol *sym;
expr = stmt->asm_string;
- if (!expr || expr->type != EXPR_STRING) {
- sparse_error(stmt->pos, "need constant string for inline asm");
+ if (!expr)
return;
- }
FOR_EACH_PTR(stmt->asm_outputs, op) {
/* Identifier */
/* Constraint */
expr = op->constraint;
- if (!expr || expr->type != EXPR_STRING) {
- sparse_error(expr ? expr->pos : stmt->pos, "asm output constraint is not a string");
- op->constraint = NULL;
- } else
+ if (expr)
verify_output_constraint(expr, expr->string->data);
/* Expression */
@@ -3553,10 +3548,7 @@ static void evaluate_asm_statement(struct statement *stmt)
/* Constraint */
expr = op->constraint;
- if (!expr || expr->type != EXPR_STRING) {
- sparse_error(expr ? expr->pos : stmt->pos, "asm input constraint is not a string");
- op->constraint = NULL;
- } else
+ if (expr)
verify_input_constraint(expr, expr->string->data);
/* Expression */