diff mbox

[v4,16/25] constexpr: recognize string literals as address constants

Message ID 20170331014459.9351-17-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show

Commit Message

Luc Van Oostenryck March 31, 2017, 1:44 a.m. UTC
From: Nicolai Stange <nicstange@gmail.com>

Introduce support for recognizing string literals as address constants.

Make evaluate_string() unconditionally tag the *-preop wrapped symbol
expression as being an address constant.

Signed-off-by: Nicolai Stange <nicstange@gmail.com>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 evaluate.c                    | 1 +
 validation/constexpr-string.c | 9 +++++++++
 2 files changed, 10 insertions(+)
 create mode 100644 validation/constexpr-string.c
diff mbox

Patch

diff --git a/evaluate.c b/evaluate.c
index 9a7d432b8..cdbc08ef2 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -108,6 +108,7 @@  static struct symbol *evaluate_string(struct expression *expr)
 	
 	addr->symbol = sym;
 	addr->ctype = &lazy_ptr_ctype;
+	addr->flags = CEF_ADDR;
 
 	expr->type = EXPR_PREOP;
 	expr->op = '*';
diff --git a/validation/constexpr-string.c b/validation/constexpr-string.c
new file mode 100644
index 000000000..e641a83eb
--- /dev/null
+++ b/validation/constexpr-string.c
@@ -0,0 +1,9 @@ 
+static char *a = "foobar";	// OK
+
+/*
+ * check-name: string literal constness verification.
+ * check-command: sparse -Wconstexpr-not-const $file
+ *
+ * check-error-start
+ * check-error-end
+ */