From 7abbb3a73980a8505038ebfcc46c47503ef315bd Mon Sep 17 00:00:00 2001 From: "Ivan R. Ivanov" Date: Thu, 26 Oct 2023 08:39:29 -0700 Subject: [PATCH] Fix bug with Opaque-ifying identified structs with non-identified members (#365) --- lib/polygeist/Passes/ConvertToOpaquePtr.cpp | 6 +++-- tools/cgeist/Test/Verification/opaquestr.cpp | 23 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tools/cgeist/Test/Verification/opaquestr.cpp diff --git a/lib/polygeist/Passes/ConvertToOpaquePtr.cpp b/lib/polygeist/Passes/ConvertToOpaquePtr.cpp index baf4ff7c9d09..8fcb7cde367b 100644 --- a/lib/polygeist/Passes/ConvertToOpaquePtr.cpp +++ b/lib/polygeist/Passes/ConvertToOpaquePtr.cpp @@ -247,8 +247,10 @@ struct ConvertToOpaquePtrPass } for (auto ty : st.getBody()) { StringRef fieldKey = ""; - if (auto fieldST = ty.dyn_cast()) - fieldKey = fieldST.getName(); + if (auto fieldST = ty.dyn_cast()) { + if (fieldST.isIdentified()) + fieldKey = fieldST.getName(); + } if (typeCache.find(fieldKey) != typeCache.end()) { bodyTypes.push_back(typeCache[fieldKey]); } else { diff --git a/tools/cgeist/Test/Verification/opaquestr.cpp b/tools/cgeist/Test/Verification/opaquestr.cpp new file mode 100644 index 000000000000..6e0343db6027 --- /dev/null +++ b/tools/cgeist/Test/Verification/opaquestr.cpp @@ -0,0 +1,23 @@ +// RUN: cgeist %s %stdinclude -S | FileCheck %s + +struct Str { + int a; + float b; +}; + +struct OperandInfo { + OperandInfo *info; + struct { + int a; + float b; + } intfloat; + Str a; + Str *b; + int c; +}; + +void *foo(OperandInfo *info) { + return info; +} + +// CHECK: memref>, struct<(i32, f32)>, struct<(i32, f32)>, memref>, i32)>>