diff mbox

fix cast to pointer to floating-point

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

Commit Message

Luc Van Oostenryck March 11, 2017, 2:16 p.m. UTC
By mistake, a cast to floating-pointer pointer was
created as OP_FPCAST instead of OP_PTRCAST.

Fix this by adding the missing 'else'.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 linearize.c                |  3 +--
 validation/fp-vs-ptrcast.c | 13 +++++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)
 create mode 100644 validation/fp-vs-ptrcast.c

Comments

Christopher Li April 25, 2017, 8:47 p.m. UTC | #1
On Sat, Mar 11, 2017 at 10:16 PM, Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
> By mistake, a cast to floating-pointer pointer was
> created as OP_FPCAST instead of OP_PTRCAST.
>
> Fix this by adding the missing 'else'.

That looks good. Good catch.

Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/linearize.c b/linearize.c
index 255231c60..6397f68a7 100644
--- a/linearize.c
+++ b/linearize.c
@@ -1119,8 +1119,7 @@  static struct instruction *alloc_cast_instruction(struct symbol *src, struct sym
 		base = base->ctype.base_type;
 		if (base != &void_ctype)
 			opcode = OP_PTRCAST;
-	}
-	if (base->ctype.base_type == &fp_type)
+	} else if (base->ctype.base_type == &fp_type)
 		opcode = OP_FPCAST;
 	return alloc_typed_instruction(opcode, ctype);
 }
diff --git a/validation/fp-vs-ptrcast.c b/validation/fp-vs-ptrcast.c
new file mode 100644
index 000000000..817aee5c9
--- /dev/null
+++ b/validation/fp-vs-ptrcast.c
@@ -0,0 +1,13 @@ 
+float *f01(void* p)
+{
+	return p;
+}
+
+/*
+ * check-name: fp-vs-ptrcast
+ * check-command: test-linearize -Wno-decl $file
+ * check-output-ignore
+ *
+ * check-output-excludes: fpcast
+ * check-output-contains: ptrcast
+ */