Skip to content

Commit

Permalink
[Driver] Fix test failures when in classic Flang mode
Browse files Browse the repository at this point in the history
Add a new lit feature tag "classic_flang" to select which tests can or cannot be
run when the driver is built for classic Flang. Handle LLVM_ENABLE_CLASSIC_FLANG
in llvm/cmake/modules/HandleLLVMOptions.cmake instead of clang/CMakeLists.txt so
that macro works in both clang and llvm.
  • Loading branch information
bryanpkc authored and kiranchandramohan committed Sep 26, 2020
1 parent f7428cd commit 815dbcc
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 7 deletions.
5 changes: 0 additions & 5 deletions clang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,6 @@ endif()

add_definitions( -D_GNU_SOURCE )

option(LLVM_ENABLE_CLASSIC_FLANG "Build support for classic Flang instead of the new built-in Flang" OFF)
if(LLVM_ENABLE_CLASSIC_FLANG)
add_definitions( -DENABLE_CLASSIC_FLANG )
endif()

option(CLANG_BUILD_TOOLS
"Build the Clang tools. If OFF, just generate build targets." ON)

Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/autocomplete.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
// FVECLIBALL: Accelerate
// FVECLIBALL-NEXT: MASSV
// FVECLIBALL-NEXT: none
// FVECLIBALL-NEXT: SVML
// FVECLIBALL: SVML
// RUN: %clang --autocomplete=-fshow-overloads= | FileCheck %s -check-prefix=FSOVERALL
// FSOVERALL: all
// FSOVERALL-NEXT: best
Expand Down
28 changes: 28 additions & 0 deletions clang/test/Driver/flang/classic_flang.f95
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
! Check that the driver can invoke flang1 and flang2 to compile Fortran with
! --driver-mode=flang (default when the file extension is .f95).

! REQUIRES: classic_flang

! RUN: %clang -target x86_64-unknown-linux-gnu -integrated-as -c %s -### 2>&1 \
! RUN: | FileCheck --check-prefix=CHECK-OBJECT %s
! CHECK-OBJECT: flang1
! CHECK-OBJECT: flang2
! CHECK-OBJECT-SAME: "-asm" [[LLFILE:.*.ll]]
! CHECK-OBJECT-NOT: cc1as
! CHECK-OBJECT: clang
! CHECK-OBJECT-SAME: -cc1
! CHECK-OBJECT-SAME: "-o" "classic_flang.o"
! CHECK-OBJECT-SAME: "-x" "ir"
! CHECK-OBJECT-SAME: [[LLFILE]]

! RUN: %clang -target x86_64-unknown-linux-gnu -integrated-as -S %s -### 2>&1 \
! RUN: | FileCheck --check-prefix=CHECK-ASM %s
! CHECK-ASM: flang1
! CHECK-ASM: flang2
! CHECK-ASM-SAME: "-asm" [[LLFILE:.*.ll]]
! CHECK-ASM-NOT: cc1as
! CHECK-ASM: clang
! CHECK-ASM-SAME: -cc1
! CHECK-ASM-SAME: "-o" "classic_flang.s"
! CHECK-ASM-SAME: "-x" "ir"
! CHECK-ASM-SAME: [[LLFILE]]
2 changes: 2 additions & 0 deletions clang/test/Driver/flang/flang.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
! Check that flang -fc1 is invoked when in --driver-mode=flang.

! UNSUPPORTED: classic_flang

! This is a copy of flang_ucase.F90 because the driver has logic in it which
! differentiates between F90 and f90 files. Flang will not treat these files
! differently.
Expand Down
2 changes: 2 additions & 0 deletions clang/test/Driver/flang/flang_ucase.F90
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
! Check that flang -fc1 is invoked when in --driver-mode=flang.

! UNSUPPORTED: classic_flang

! This is a copy of flang.f90 because the driver has logic in it which
! differentiates between F90 and f90 files. Flang will not treat these files
! differently.
Expand Down
2 changes: 2 additions & 0 deletions clang/test/Driver/flang/multiple-inputs-mixed.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
! Check that flang can handle mixed C and fortran inputs.

! UNSUPPORTED: classic_flang

! RUN: %clang --driver-mode=flang -### -fsyntax-only %S/Inputs/one.f90 %S/Inputs/other.c 2>&1 | FileCheck --check-prefixes=CHECK-SYNTAX-ONLY %s
! CHECK-SYNTAX-ONLY-LABEL: "{{[^"]*}}flang{{[^"/]*}}" "-fc1"
! CHECK-SYNTAX-ONLY: "{{[^"]*}}/Inputs/one.f90"
Expand Down
2 changes: 2 additions & 0 deletions clang/test/Driver/flang/multiple-inputs.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
! Check that flang driver can handle multiple inputs at once.

! UNSUPPORTED: classic_flang

! RUN: %clang --driver-mode=flang -### -fsyntax-only %S/Inputs/one.f90 %S/Inputs/two.f90 2>&1 | FileCheck --check-prefixes=CHECK-SYNTAX-ONLY %s
! CHECK-SYNTAX-ONLY-LABEL: "{{[^"]*}}flang" "-fc1"
! CHECK-SYNTAX-ONLY: "{{[^"]*}}/Inputs/one.f90"
Expand Down
2 changes: 2 additions & 0 deletions clang/test/Driver/fortran.f95
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
! Check that the clang driver can invoke gcc to compile Fortran when in
! --driver-mode=clang. This is legacy behaviour - see also --driver-mode=flang.

! UNSUPPORTED: classic_flang

! RUN: %clang -target x86_64-unknown-linux-gnu -integrated-as -c %s -### 2>&1 \
! RUN: | FileCheck --check-prefix=CHECK-OBJECT %s
! CHECK-OBJECT: gcc
Expand Down
4 changes: 3 additions & 1 deletion clang/test/Driver/gfortran.f90
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
! Test that Clang can forward all of the flags which are documented as
! being supported by gfortran to GCC when falling back to GCC for
! a fortran input file.
!

! UNSUPPORTED: classic_flang

! RUN: %clang -no-canonical-prefixes -target i386-linux -### %s -o %t 2>&1 \
! RUN: -Aquestion=answer \
! RUN: -A-question=answer \
Expand Down
3 changes: 3 additions & 0 deletions clang/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,6 @@ def calculate_arch_features(arch_string):

if config.enable_shared:
config.available_features.add("enable_shared")

if config.use_classic_flang:
config.available_features.add("classic_flang")
1 change: 1 addition & 0 deletions clang/test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ config.host_arch = "@HOST_ARCH@"
config.python_executable = "@PYTHON_EXECUTABLE@"
config.use_z3_solver = lit_config.params.get('USE_Z3_SOLVER', "@USE_Z3_SOLVER@")
config.has_plugins = @LLVM_ENABLE_PLUGINS@
config.use_classic_flang = @LLVM_ENABLE_CLASSIC_FLANG@

# Support substitution of the tools and libs dirs with user parameters. This is
# used when we can't determine the tool dir at configuration time.
Expand Down
8 changes: 8 additions & 0 deletions llvm/cmake/modules/HandleLLVMOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ if( LLVM_ENABLE_ASSERTIONS )
endif()
endif()

option(LLVM_ENABLE_CLASSIC_FLANG "Build support for classic Flang instead of the new built-in Flang" OFF)
if(LLVM_ENABLE_CLASSIC_FLANG)
set(LLVM_ENABLE_CLASSIC_FLANG 1)
add_definitions( -DENABLE_CLASSIC_FLANG )
else()
set(LLVM_ENABLE_CLASSIC_FLANG 0)
endif()

if(LLVM_ENABLE_EXPENSIVE_CHECKS)
add_definitions(-DEXPENSIVE_CHECKS)
add_definitions(-D_GLIBCXX_DEBUG)
Expand Down
16 changes: 16 additions & 0 deletions llvm/lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4941,6 +4941,7 @@ bool LLParser::ParseDITemplateValueParameter(MDNode *&Result, bool IsDistinct) {
/// isDefinition: true, templateParams: !3,
/// declaration: !4, align: 8)
bool LLParser::ParseDIGlobalVariable(MDNode *&Result, bool IsDistinct) {
#ifdef ENABLE_CLASSIC_FLANG
#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
OPTIONAL(name, MDStringField, (/* AllowEmpty */ true)); \
OPTIONAL(scope, MDField, ); \
Expand All @@ -4954,6 +4955,21 @@ bool LLParser::ParseDIGlobalVariable(MDNode *&Result, bool IsDistinct) {
OPTIONAL(declaration, MDField, ); \
OPTIONAL(flags, DIFlagField, ); \
OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX));
#else
#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
REQUIRED(name, MDStringField, (/* AllowEmpty */ false)); \
OPTIONAL(scope, MDField, ); \
OPTIONAL(linkageName, MDStringField, ); \
OPTIONAL(file, MDField, ); \
OPTIONAL(line, LineField, ); \
OPTIONAL(type, MDField, ); \
OPTIONAL(isLocal, MDBoolField, ); \
OPTIONAL(isDefinition, MDBoolField, (true)); \
OPTIONAL(templateParams, MDField, ); \
OPTIONAL(declaration, MDField, ); \
OPTIONAL(flags, DIFlagField, ); \
OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX));
#endif
PARSE_MD_FIELDS();
#undef VISIT_MD_FIELDS

Expand Down
1 change: 1 addition & 0 deletions llvm/test/Assembler/invalid-diglobalvariable-empty-name.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
; UNSUPPORTED: classic_flang

; CHECK: <stdin>:[[@LINE+1]]:30: error: 'name' cannot be empty
!0 = !DIGlobalVariable(name: "")
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
; UNSUPPORTED: classic_flang

; CHECK: <stdin>:[[@LINE+1]]:24: error: missing required field 'name'
!0 = !DIGlobalVariable()
3 changes: 3 additions & 0 deletions llvm/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,6 @@ def have_ld64_plugin_support():

if config.have_opt_viewer_modules:
config.available_features.add('have_opt_viewer_modules')

if config.use_classic_flang:
config.available_features.add("classic_flang")
1 change: 1 addition & 0 deletions llvm/test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ config.have_opt_viewer_modules = @LLVM_HAVE_OPT_VIEWER_MODULES@
config.libcxx_used = @LLVM_LIBCXX_USED@
config.has_plugins = @LLVM_ENABLE_PLUGINS@
config.linked_bye_extension = @LLVM_BYE_LINK_INTO_TOOLS@
config.use_classic_flang = @LLVM_ENABLE_CLASSIC_FLANG@

# Support substitution of the tools_dir with user parameters. This is
# used when we can't determine the tool dir at configuration time.
Expand Down

0 comments on commit 815dbcc

Please sign in to comment.