Skip to content

Commit fa50204

Browse files
author
Salinas, David
authored
[Flang] Emit warning when AMD Next-gen Fortran Compiler is invoked as 'amdflang-new' (llvm#1458)
2 parents 3de1e5d + 0f9a104 commit fa50204

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

clang/lib/Driver/ToolChain.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,18 @@ static std::string normalizeProgramName(llvm::StringRef Argv0) {
451451
return ProgName;
452452
}
453453

454-
static const DriverSuffix *parseDriverSuffix(StringRef ProgName, size_t &Pos) {
454+
static const DriverSuffix *parseDriverSuffix(StringRef ProgName, size_t &Pos, bool &FlangNew) {
455455
// Try to infer frontend type and default target from the program name by
456456
// comparing it against DriverSuffixes in order.
457457

458+
// Part I: Warn if invocation happens with flang-new (for Flang); this is for
459+
// the time being and should be removed once AMD Classic Flang has been
460+
// removed from ROCm.
461+
FlangNew = false;
462+
if (ProgName.ends_with("flang-new")) {
463+
FlangNew = true;
464+
}
465+
458466
// If there is a match, the function tries to identify a target as prefix.
459467
// E.g. "x86_64-linux-clang" as interpreted as suffix "clang" with target
460468
// prefix "x86_64-linux". If such a target prefix is found, it may be
@@ -488,7 +496,22 @@ ParsedClangName
488496
ToolChain::getTargetAndModeFromProgramName(StringRef PN) {
489497
std::string ProgName = normalizeProgramName(PN);
490498
size_t SuffixPos;
491-
const DriverSuffix *DS = parseDriverSuffix(ProgName, SuffixPos);
499+
bool FlangNew = false;
500+
const DriverSuffix *DS = parseDriverSuffix(ProgName, SuffixPos, FlangNew);
501+
502+
// Part II: Warn if invocation happens with flang-new (for Flang); this is for
503+
// the time being and should be removed once AMD Classic Flang has been
504+
// removed from ROCm.
505+
if (FlangNew) {
506+
if (!::getenv("AMD_NOWARN_FLANG_NEW")) {
507+
// The solution with "llvm::errs()" is not ideal, but the driver object
508+
// is not been constructed yet, so we cannot use the Diag() infrastructure
509+
// for this.
510+
llvm::errs() << "warning: the 'amdflang-new' and 'flang-new' commmands "
511+
"have been deprecated; please use 'amdflang' instead\n";
512+
}
513+
}
514+
492515
if (!DS)
493516
return {};
494517
size_t SuffixEnd = SuffixPos + strlen(DS->Suffix);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
! RUN: amdflang-new -c %s 2>&1 | FileCheck %s
2+
! CHECK: warning: the 'amdflang-new' and 'flang-new' commmands have been deprecated; please use 'amdflang' instead

0 commit comments

Comments
 (0)