Author: erichkeane Date: 2025-03-07T08:05:19-08:00 New Revision: 67960e5c08629bb78c147bd0a86764967448b33c
URL: https://github.com/llvm/llvm-project/commit/67960e5c08629bb78c147bd0a86764967448b33c DIFF: https://github.com/llvm/llvm-project/commit/67960e5c08629bb78c147bd0a86764967448b33c.diff LOG: [OpenACC] Ensure decl OpenACC constructs don't crash I initially implemented codegen to be a 'no-op' for these declarations, which I thought was properly implemented. However, when they are a top-level decl, we have a separate switch. This patch makes sure they are properly emitted at top-level as a no-op, and adds a test for both top-level and not top-level. Added: clang/test/CodeGen/openacc-noop-decl.c Modified: clang/lib/CodeGen/CodeGenModule.cpp clang/lib/CodeGen/CodeGenModule.h Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index bca0a932b3495..d2c97ce501b03 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -7300,6 +7300,13 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { getHLSLRuntime().addBuffer(cast<HLSLBufferDecl>(D)); break; + case Decl::OpenACCDeclare: + EmitOpenACCDeclare(cast<OpenACCDeclareDecl>(D)); + break; + case Decl::OpenACCRoutine: + EmitOpenACCRoutine(cast<OpenACCRoutineDecl>(D)); + break; + default: // Make sure we handled everything we should, every other kind is a // non-top-level decl. FIXME: Would be nice to have an isTopLevelDeclKind diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index 83bb5bc54d077..e7c923834238f 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -1574,9 +1574,11 @@ class CodeGenModule : public CodeGenTypeCache { CodeGenFunction *CGF = nullptr); // Emit code for the OpenACC Declare declaration. - void EmitOpenACCDeclare(const OpenACCDeclareDecl *D, CodeGenFunction *CGF); + void EmitOpenACCDeclare(const OpenACCDeclareDecl *D, + CodeGenFunction *CGF = nullptr); // Emit code for the OpenACC Routine declaration. - void EmitOpenACCRoutine(const OpenACCRoutineDecl *D, CodeGenFunction *CGF); + void EmitOpenACCRoutine(const OpenACCRoutineDecl *D, + CodeGenFunction *CGF = nullptr); /// Emit a code for requires directive. /// \param D Requires declaration diff --git a/clang/test/CodeGen/openacc-noop-decl.c b/clang/test/CodeGen/openacc-noop-decl.c new file mode 100644 index 0000000000000..41f756d835aa5 --- /dev/null +++ b/clang/test/CodeGen/openacc-noop-decl.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +// Check to ensure these are no-ops/don't really do anything. +void name(); + +void foo() { +#pragma acc declare + // CHECK-NOT: declare +#pragma acc routine(name) worker + // CHECK-NOT: routine +} +#pragma acc declare + // CHECK-NOT: declare +#pragma acc routine(name) worker + // CHECK-NOT: routine _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits