[PATCH v1 12/18] add PSEUDO_UNDEF & undef_pseudo()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Processing in the middle-end are much easier if undefined values
have been clearly identified. Once done, we can then make
choices like:
- give some warnings about uninitialized variables
- always initialize them to zero
- allow arbitraly simplification
- ...

Prepare this by declaring a new type of pseudo: PSEUDO_UNDEF
somewhat similar to PSEUDO_VOID.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 linearize.c   | 9 +++++++++
 linearize.h   | 4 +++-
 sparse-llvm.c | 6 ++++++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/linearize.c b/linearize.c
index be0e811f2..4cd2c75eb 100644
--- a/linearize.c
+++ b/linearize.c
@@ -171,6 +171,8 @@ const char *show_pseudo(pseudo_t pseudo)
 		if (pseudo->ident)
 			sprintf(buf+i, "(%s)", show_ident(pseudo->ident));
 		break;
+	case PSEUDO_UNDEF:
+		return "UNDEF";
 	default:
 		snprintf(buf, 64, "<bad pseudo type %d>", pseudo->type);
 	}
@@ -820,6 +822,13 @@ pseudo_t value_pseudo(long long val)
 	return pseudo;
 }
 
+pseudo_t undef_pseudo(void)
+{
+	pseudo_t pseudo = __alloc_pseudo(0);
+	pseudo->type = PSEUDO_UNDEF;
+	return pseudo;
+}
+
 static pseudo_t argument_pseudo(struct entrypoint *ep, int nr)
 {
 	pseudo_t pseudo = __alloc_pseudo(0);
diff --git a/linearize.h b/linearize.h
index 486cf5979..0285e28d3 100644
--- a/linearize.h
+++ b/linearize.h
@@ -21,6 +21,7 @@ DECLARE_PTR_LIST(pseudo_user_list, struct pseudo_user);
 
 enum pseudo_type {
 	PSEUDO_VOID,
+	PSEUDO_UNDEF,
 	PSEUDO_REG,
 	PSEUDO_SYM,
 	PSEUDO_VAL,
@@ -323,7 +324,7 @@ static inline void add_pseudo_user_ptr(struct pseudo_user *user, struct pseudo_u
 
 static inline int has_use_list(pseudo_t p)
 {
-	return (p && p->type != PSEUDO_VOID && p->type != PSEUDO_VAL);
+	return (p && p->type != PSEUDO_VOID && p->type != PSEUDO_UNDEF && p->type != PSEUDO_VAL);
 }
 
 static inline int pseudo_user_list_size(struct pseudo_user_list *list)
@@ -380,6 +381,7 @@ struct instruction *alloc_phisrc(pseudo_t pseudo, struct symbol *type);
 pseudo_t alloc_phi(struct basic_block *source, pseudo_t pseudo, struct symbol *type);
 pseudo_t alloc_pseudo(struct instruction *def);
 pseudo_t value_pseudo(long long val);
+pseudo_t undef_pseudo(void);
 
 struct entrypoint *linearize_symbol(struct symbol *sym);
 int unssa(struct entrypoint *ep);
diff --git a/sparse-llvm.c b/sparse-llvm.c
index b22d2f67b..e2811b062 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -270,6 +270,9 @@ static const char *pseudo_name(pseudo_t pseudo, char *buf)
 	case PSEUDO_VOID:
 		buf[0] = '\0';
 		break;
+	case PSEUDO_UNDEF:
+		assert(0);
+		break;
 	default:
 		assert(0);
 	}
@@ -387,6 +390,9 @@ static LLVMValueRef pseudo_to_value(struct function *fn, struct symbol *ctype, p
 	case PSEUDO_VOID:
 		result = NULL;
 		break;
+	case PSEUDO_UNDEF:
+		result = LLVMGetUndef(symbol_type(ctype));
+		break;
 	default:
 		assert(0);
 	}
-- 
2.16.2

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



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux