[SPARSE PATCH 3/5] do not issue a branch to non-existent label

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

 



If the label doesn't exist, the corresponding BB will never
be created and the CFG will be invalid.

So, do not issue the branch for goto to these labels.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 linearize.c                         | 13 +++++++++++--
 validation/linear/invalid-labels0.c |  1 -
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/linearize.c b/linearize.c
index b040d345d469..4e9f9b3693e9 100644
--- a/linearize.c
+++ b/linearize.c
@@ -2379,6 +2379,7 @@ static pseudo_t linearize_statement(struct entrypoint *ep, struct statement *stm
 	}
 
 	case STMT_GOTO: {
+		struct symbol *label;
 		struct symbol *sym;
 		struct expression *expr;
 		struct instruction *goto_ins;
@@ -2389,8 +2390,16 @@ static pseudo_t linearize_statement(struct entrypoint *ep, struct statement *stm
 		if (!bb_reachable(active))
 			break;
 
-		if (stmt->goto_label) {
-			add_goto(ep, get_bound_block(ep, stmt->goto_label));
+		label = stmt->goto_label;
+		if (label) {
+			if (!label->stmt) {
+				// do not issue a branch to non-existent labels
+				if (label->namespace == NS_LABEL)
+					break;
+				if (label->namespace == NS_NONE)
+					break;
+			}
+			add_goto(ep, get_bound_block(ep, label));
 			break;
 		}
 
diff --git a/validation/linear/invalid-labels0.c b/validation/linear/invalid-labels0.c
index ae3bf7283fb8..a15e9d434011 100644
--- a/validation/linear/invalid-labels0.c
+++ b/validation/linear/invalid-labels0.c
@@ -11,7 +11,6 @@ void bar(void)
 /*
  * check-name: invalid-labels0
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-excludes: END
-- 
2.26.0




[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