mirror of
https://github.com/intel/llvm.git
synced 2026-01-22 23:49:22 +08:00
[flang][cuda] Define _CUDA only when preprocessor is enabled (#155913)
From the CUDA Fortran programming guide: > If CUDA Fortran is enabled in compilation, either by specifying -cuda on the command line, and pre-processing is enabled by either the -Mpreprocess compiler option or by using capital letters in the filename extension (.CUF, .F90, etc.) then the _CUDA macro is defined. Move the definition of `_CUDA` to the compiler invocation.
This commit is contained in:
committed by
GitHub
parent
11e796dee2
commit
1277a1111d
@@ -1754,6 +1754,11 @@ void CompilerInvocation::setDefaultPredefinitions() {
|
||||
fortranOptions.predefinitions);
|
||||
}
|
||||
|
||||
if (frontendOptions.features.IsEnabled(
|
||||
Fortran::common::LanguageFeature::CUDA)) {
|
||||
fortranOptions.predefinitions.emplace_back("_CUDA", "1");
|
||||
}
|
||||
|
||||
llvm::Triple targetTriple{llvm::Triple(this->targetOpts.triple)};
|
||||
if (targetTriple.isOSLinux()) {
|
||||
fortranOptions.predefinitions.emplace_back("__linux__", "1");
|
||||
|
||||
@@ -96,9 +96,6 @@ const SourceFile *Parsing::Prescan(const std::string &path, Options options) {
|
||||
prescanner.AddCompilerDirectiveSentinel("$cuf");
|
||||
prescanner.AddCompilerDirectiveSentinel("@cuf");
|
||||
}
|
||||
if (options.features.IsEnabled(LanguageFeature::CUDA)) {
|
||||
preprocessor_.Define("_CUDA", "1");
|
||||
}
|
||||
ProvenanceRange range{allSources.AddIncludedFile(
|
||||
*sourceFile, ProvenanceRange{}, options.isModuleFile)};
|
||||
prescanner.Prescan(range);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
! RUN: %flang_fc1 -fdebug-dump-parse-tree %s 2>&1 | FileCheck %s
|
||||
! RUN: %flang_fc1 -fdebug-dump-parse-tree -x cuda %s 2>&1 | FileCheck %s
|
||||
include "cuf-sanity-common"
|
||||
!CHECK: Program -> ProgramUnit -> SubroutineSubprogram
|
||||
!CHECK: | SubroutineStmt
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
|
||||
! RUN: %flang_fc1 -fdebug-unparse -x cuda %s 2>&1 | FileCheck %s
|
||||
include "cuf-sanity-common"
|
||||
!CHECK: SUBROUTINE atcuf
|
||||
!CHECK: END SUBROUTINE
|
||||
|
||||
Reference in New Issue
Block a user