Skip to content

Commit 89a9db4

Browse files
cotiRichBarton-Arm
authored andcommitted
[flang] Version information in flang/f18
Fixed some version information in flang/f18: - fixed the behavior of the -v switch: this flag enables verbosity with used with arguments, but just displays the version when used alone (related to this bug: https://bugs.llvm.org/show_bug.cgi?id=46017) - added __FLANG, __FLANG_MAJOR__, __FLANG_MINOR__ and __FLANG_PATCHLEVEL__ (similar to their __F18* counterparts) for compatibility purpose Reviewed By: sscalpone, AlexisPerry, richard.barton.arm, tskeith Differential Revision: https://reviews.llvm.org/D84334
1 parent b34ec59 commit 89a9db4

File tree

5 files changed

+48
-6
lines changed

5 files changed

+48
-6
lines changed

flang/test/Driver/version_test.f90

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
! Check that lit configuration works by checking the compiler version
22

3-
! RUN: %f18 -V 2>&1 | FileCheck -check-prefix=VERSION %s
43
! VERSION-NOT:{{![[:space:]]}}
54
! VERSION:{{[[:space:]]}}
6-
! VERSION-SAME:f18 compiler (under development)
5+
! VERSION-SAME:f18 compiler (under development), version {{[1-9][0-9]*.[0-9]*.[0-9]*}}
76
! VERSION-EMPTY:
7+
8+
! RUN: %f18 -V 2>&1 | FileCheck -check-prefix=VERSION %s
9+
! RUN: %f18 -v 2>&1 | FileCheck -check-prefix=VERSION %s
10+
! RUN: %f18 --version 2>&1 | FileCheck -check-prefix=VERSION %s
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
! Check that the macros that give the verion number are set properly
2+
3+
!CHECK: flang_major = {{[1-9][0-9]*$}}
4+
!CHECK: flang_minor = {{[0-9]+$}}
5+
!CHECK: flang_patchlevel = {{[0-9]+$}}
6+
!RUN: %f18 -E %s | FileCheck --ignore-case %s
7+
8+
9+
integer, parameter :: flang_major = __flang_major__
10+
integer, parameter :: flang_minor = __flang_minor__
11+
integer, parameter :: flang_patchlevel = __flang_patchlevel__
12+

flang/tools/f18/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,6 @@ endif()
8080
# The flang script to be installed needs a different path to the headers.
8181
set(FLANG_INTRINSIC_MODULES_DIR ${CMAKE_INSTALL_PREFIX}/include/flang)
8282
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/flang.sh.in ${FLANG_BINARY_DIR}/bin/flang-install.sh @ONLY)
83+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/f18_version.h.in ${CMAKE_CURRENT_BINARY_DIR}/f18_version.h @ONLY)
8384

8485
install(PROGRAMS ${FLANG_BINARY_DIR}/bin/flang-install.sh DESTINATION bin RENAME flang PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE)

flang/tools/f18/f18.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include <unistd.h>
3939
#include <vector>
4040

41+
#include "f18_version.h"
42+
4143
static std::list<std::string> argList(int argc, char *const argv[]) {
4244
std::list<std::string> result;
4345
for (int j = 0; j < argc; ++j) {
@@ -391,6 +393,13 @@ void Link(std::vector<std::string> &liblist, std::vector<std::string> &objects,
391393
}
392394
}
393395

396+
int printVersion() {
397+
llvm::errs() << "\nf18 compiler (under development), version "
398+
<< __FLANG_MAJOR__ << "." << __FLANG_MINOR__ << "."
399+
<< __FLANG_PATCHLEVEL__ << "\n";
400+
return exitStatus;
401+
}
402+
394403
int main(int argc, char *const argv[]) {
395404

396405
atexit(CleanUpAtExit);
@@ -412,6 +421,11 @@ int main(int argc, char *const argv[]) {
412421
options.predefinitions.emplace_back("__F18_MAJOR__", "1");
413422
options.predefinitions.emplace_back("__F18_MINOR__", "1");
414423
options.predefinitions.emplace_back("__F18_PATCHLEVEL__", "1");
424+
options.predefinitions.emplace_back("__flang__", __FLANG__);
425+
options.predefinitions.emplace_back("__flang_major__", __FLANG_MAJOR__);
426+
options.predefinitions.emplace_back("__flang_minor__", __FLANG_MINOR__);
427+
options.predefinitions.emplace_back(
428+
"__flang_patchlevel__", __FLANG_PATCHLEVEL__);
415429
#if __x86_64__
416430
options.predefinitions.emplace_back("__x86_64__", "1");
417431
#endif
@@ -661,13 +675,16 @@ int main(int argc, char *const argv[]) {
661675
<< "Unrecognised options are passed through to the external compiler\n"
662676
<< "set by F18_FC (see defaults).\n";
663677
return exitStatus;
664-
} else if (arg == "-V") {
665-
llvm::errs() << "\nf18 compiler (under development)\n";
666-
return exitStatus;
678+
} else if (arg == "-V" || arg == "--version") {
679+
return printVersion();
667680
} else {
668681
driver.F18_FCArgs.push_back(arg);
669682
if (arg == "-v") {
670-
driver.verbose = true;
683+
if (args.size() > 1) {
684+
driver.verbose = true;
685+
} else {
686+
return printVersion();
687+
}
671688
} else if (arg == "-I") {
672689
driver.F18_FCArgs.push_back(args.front());
673690
driver.searchDirectories.push_back(args.front());

flang/tools/f18/f18_version.h.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef _F18_H_
2+
#define _F18_H_
3+
4+
#define __FLANG__ "1"
5+
#define __FLANG_MAJOR__ "@LLVM_VERSION_MAJOR@"
6+
#define __FLANG_MINOR__ "@LLVM_VERSION_MINOR@"
7+
#define __FLANG_PATCHLEVEL__ "@LLVM_VERSION_PATCH@"
8+
9+
#endif // _F18_H_

0 commit comments

Comments
 (0)