From 15fd589a62de4034042adb1d1385e99b957ae8b9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20B=C3=BChler?= <david.buhler@cea.fr>
Date: Fri, 23 Jun 2023 14:26:06 +0200
Subject: [PATCH] [kernel] Printer_tag: catches Not_found exception when
 calling Globals.Type.global

Fixes crash in Ivette and the GTK GUI on files with undefined type.
No tag is created on undefined types.
---
 .../ast_printing/printer_tag.ml               | 24 ++++++++++++-------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/kernel_services/ast_printing/printer_tag.ml b/src/kernel_services/ast_printing/printer_tag.ml
index dc3f0d40495..ffe3da9c20d 100644
--- a/src/kernel_services/ast_printing/printer_tag.ml
+++ b/src/kernel_services/ast_printing/printer_tag.ml
@@ -840,19 +840,25 @@ struct
         super#fkind c
 
     method! compname fmt comp =
-      Format.fprintf fmt "@{<%s>%a@}"
-        (Info.tag (PGlobal(Globals.Types.global Struct comp.cname)))
-        super#compname comp
+      try
+        Format.fprintf fmt "@{<%s>%a@}"
+          (Info.tag (PGlobal(Globals.Types.global Struct comp.cname)))
+          super#compname comp
+      with Not_found -> super#compname fmt comp
 
     method! enuminfo fmt enum =
-      Format.fprintf fmt "@{<%s>%a@}"
-        (Info.tag (PGlobal(Globals.Types.global Enum enum.ename)))
-        super#enuminfo enum
+      try
+        Format.fprintf fmt "@{<%s>%a@}"
+          (Info.tag (PGlobal(Globals.Types.global Enum enum.ename)))
+          super#enuminfo enum
+      with Not_found -> super#enuminfo fmt enum
 
     method! typeinfo fmt tinfo =
-      Format.fprintf fmt "@{<%s>%a@}"
-        (Info.tag (PGlobal(Globals.Types.global Typedef tinfo.tname)))
-        super#typeinfo tinfo
+      try
+        Format.fprintf fmt "@{<%s>%a@}"
+          (Info.tag (PGlobal(Globals.Types.global Typedef tinfo.tname)))
+          super#typeinfo tinfo
+      with Not_found -> super#typeinfo fmt tinfo
 
     initializer force_brace <- true
 
-- 
GitLab