[flang-commits] [flang] [mlir] [mlir][debuginfo] Add support for subprogram annotations (PR #110946)
Walter Erquinigo via flang-commits
flang-commits at lists.llvm.org
Mon Oct 7 12:21:40 PDT 2024
================
@@ -245,12 +245,24 @@ DISubprogramAttr DebugImporter::translateImpl(llvm::DISubprogram *node) {
if (llvm::is_contained(retainedNodes, nullptr))
retainedNodes.clear();
+ SmallVector<DINodeAttr> annotations;
+ if (llvm::DINodeArray rawAnns = node->getAnnotations(); rawAnns) {
+ for (size_t i = 0, e = rawAnns->getNumOperands(); i < e; ++i) {
+ const llvm::MDTuple *tuple = cast<llvm::MDTuple>(rawAnns->getOperand(i));
+ const auto name = StringAttr::get(
+ context, cast<llvm::MDString>(tuple->getOperand(0))->getString());
+ const auto value = StringAttr::get(
+ context, cast<llvm::MDString>(tuple->getOperand(1))->getString());
+ annotations.push_back(DIAnnotationAttr::get(context, name, value));
----------------
walter-erquinigo wrote:
> You said that you only support string annotations for now, but that there might be others, right? If that's correct, this will cause crashes if we hit such cases in the import.
It might be sensible to use dyn_cast and skip this part
I'm only adding support for strings because this is the only case that I've seen people using annotations with, and I don't see the need to make it more complex. At some point, if someone needs a more complex structure, they could improve these definitions.
And yes, using `dyn_cast` is a pretty good idea!
https://github.com/llvm/llvm-project/pull/110946
More information about the flang-commits
mailing list