From c10f9e73033f5ee95b1dc6b0c6de52a74b718ab6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20G=C3=B6rdes?= <michael.goerdes@fau.de>
Date: Sun, 20 Feb 2022 09:26:11 +0100
Subject: [PATCH] Prevent basic blocks without name

---
 lib/IR/Value.cpp | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lib/IR/Value.cpp b/lib/IR/Value.cpp
index 295d6ecf0db..5723cd63271 100644
--- a/lib/IR/Value.cpp
+++ b/lib/IR/Value.cpp
@@ -293,6 +293,15 @@ void Value::setNameImpl(const Twine &NewName) {
 }
 
 void Value::setName(const Twine &NewName) {
+  // Prevent basic blocks without name
+  if (BasicBlock *BB = dyn_cast<BasicBlock>(this))
+    if (NewName.isTriviallyEmpty()) {
+      static int unnamedCounter = 0;
+      std::string bbName = "unnamed_BB_" + std::to_string(unnamedCounter++);
+      setNameImpl(bbName);
+      return; // Asumption: we are not a function if we are a basic block
+    }
+
   setNameImpl(NewName);
   if (Function *F = dyn_cast<Function>(this))
     F->recalculateIntrinsicID();
-- 
GitLab