[clang] [CIR] Fix -fopenacc crash on functions without a declaration (PR #230338)
Morris Hafner via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 8 18:48:43 PDT 2026
https://github.com/mmha created https://github.com/llvm/llvm-project/pull/230338
Functions that CIRGen create such as the atomic functions coming from `createRuntimeFunction` have no declaration. These cannot have an OpenACC routine decl. Check for the existence of a declaration first.
>From 05bbac897ecf8026598c9097888c98afe91537c1 Mon Sep 17 00:00:00 2001
From: Morris Hafner <mhafner at nvidia.com>
Date: Wed, 7 Oct 2026 03:19:46 +0000
Subject: [PATCH] [CIR] Fix -fopenacc crash on functions without a declaration
Functions that CIRGen create such as the atomic functions coming from createRuntimeFunction have no declaration. These cannot have an OpenACC routine decl. Check for the existence of a declaration first.
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
---
clang/lib/CIR/CodeGen/CIRGenModule.cpp | 2 +-
clang/test/CIR/CodeGen/builtin-atomic-is-lock-free.c | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 523b0356be3103..3b15bc136899f5 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -3737,7 +3737,7 @@ CIRGenModule::createCIRFunction(mlir::Location loc, StringRef name,
// library entity.
setFuncInfoAttr(func, funcDecl);
- if (this->getLangOpts().OpenACC) {
+ if (funcDecl && this->getLangOpts().OpenACC) {
// We only have to handle this attribute, since OpenACCAnnotAttrs are
// handled via the end-of-TU work.
for (const auto *attr :
diff --git a/clang/test/CIR/CodeGen/builtin-atomic-is-lock-free.c b/clang/test/CIR/CodeGen/builtin-atomic-is-lock-free.c
index 2d13ec37a4c2af..5416f275eae8d3 100644
--- a/clang/test/CIR/CodeGen/builtin-atomic-is-lock-free.c
+++ b/clang/test/CIR/CodeGen/builtin-atomic-is-lock-free.c
@@ -4,6 +4,8 @@
// RUN: FileCheck --check-prefixes=LLVM,LLVMCIR --input-file=%t-cir.ll %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
// RUN: FileCheck --check-prefixes=LLVM,OGCG --input-file=%t.ll %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenacc -fclangir -emit-cir %s -o %t-acc.cir
+// RUN: FileCheck --check-prefix=CIR --input-file=%t-acc.cir %s
typedef struct { char buf[24]; } Big;
More information about the cfe-commits
mailing list