Skip to content

Commit 112ddd7

Browse files
committed
semantic: internal gfortran compiler excluded
1 parent 4afa3c8 commit 112ddd7

File tree

3 files changed

+37
-32
lines changed

3 files changed

+37
-32
lines changed

bear/src/semantic/interpreters/compilers/compiler_recognition.rs

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,16 @@ static DEFAULT_PATTERNS: LazyLock<Vec<(CompilerType, Regex)>> = LazyLock::new(||
6262
Regex::new(&full_pattern).unwrap_or_else(|_| panic!("Invalid regex pattern: {}", full_pattern))
6363
}
6464
vec![
65-
// simple cc pattern: matches cc
66-
(CompilerType::Gcc, create_compiler_regex(r"(?:[^/]*-)?cc", false)),
67-
// GCC pattern: matches cc, c++ and gcc cross compilation variants and versioned variants
68-
(CompilerType::Gcc, create_compiler_regex(r"(?:[^/]*-)?(?:gcc|g\+\+|c\+\+)", true)),
65+
// simple cc and c++ (no version support)
66+
(CompilerType::Gcc, create_compiler_regex(r"(?:[^/]*-)?(?:cc|c\+\+)", false)),
67+
// GCC pattern
68+
(CompilerType::Gcc, create_compiler_regex(r"(?:[^/]*-)?(?:gcc|g\+\+|gfortran|egfortran|f95)", true)),
6969
// GCC internal executables pattern: matches GCC's internal compiler phases
70-
// These are implementation details of GCC's compilation process that should be
71-
// routed to GccInterpreter for proper handling (typically to be ignored).
72-
// Examples: cc1, cc1plus, cc1obj, cc1objplus, collect2, lto1
73-
(CompilerType::Gcc, create_compiler_regex(r"(?:cc1(?:plus|obj|objplus)?|collect2|lto1)", false)),
70+
(CompilerType::Gcc, create_compiler_regex(r"(?:cc1(?:plus|obj|objplus)?|f951|collect2|lto1)", false)),
7471
// Clang pattern: matches clang, clang++, cross-compilation variants, and versioned variants
7572
(CompilerType::Clang, create_compiler_regex(r"(?:[^/]*-)?clang(?:\+\+)?", true)),
76-
// Fortran pattern: matches gfortran, flang, f77, f90, f95, f03, f08, cross-compilation variants, and versioned variants
77-
(
78-
CompilerType::Flang,
79-
create_compiler_regex(r"(?:[^/]*-)?(?:gfortran|flang|f77|f90|f95|f03|f08)", true),
80-
),
73+
// Fortran pattern: matches flang, cross-compilation variants, and versioned variants
74+
(CompilerType::Flang, create_compiler_regex(r"(?:[^/]*-)?(?:flang|flang-new)", true)),
8175
// Intel Fortran pattern: matches ifort, ifx, and versioned variants
8276
(CompilerType::IntelFortran, create_compiler_regex(r"(?:ifort|ifx)", true)),
8377
// Cray Fortran pattern: matches crayftn, ftn
@@ -343,10 +337,9 @@ mod tests {
343337
assert_eq!(recognizer.recognize(path("clang-15.exe")), Some(CompilerType::Clang));
344338

345339
// Fortran with .exe extensions
346-
assert_eq!(recognizer.recognize(path("gfortran.exe")), Some(CompilerType::Flang));
340+
assert_eq!(recognizer.recognize(path("gfortran.exe")), Some(CompilerType::Gcc));
347341
assert_eq!(recognizer.recognize(path("flang.exe")), Some(CompilerType::Flang));
348-
assert_eq!(recognizer.recognize(path("f77.exe")), Some(CompilerType::Flang));
349-
assert_eq!(recognizer.recognize(path("f90.exe")), Some(CompilerType::Flang));
342+
assert_eq!(recognizer.recognize(path("f95.exe")), Some(CompilerType::Gcc));
350343

351344
// Intel Fortran with .exe extensions
352345
assert_eq!(recognizer.recognize(path("ifort.exe")), Some(CompilerType::IntelFortran));
@@ -379,21 +372,18 @@ mod tests {
379372
let recognizer = CompilerRecognizer::new();
380373

381374
// Basic Fortran names
382-
assert_eq!(recognizer.recognize(path("gfortran")), Some(CompilerType::Flang));
375+
assert_eq!(recognizer.recognize(path("gfortran")), Some(CompilerType::Gcc));
376+
assert_eq!(recognizer.recognize(path("f95")), Some(CompilerType::Gcc));
383377
assert_eq!(recognizer.recognize(path("flang")), Some(CompilerType::Flang));
384-
assert_eq!(recognizer.recognize(path("f77")), Some(CompilerType::Flang));
385-
assert_eq!(recognizer.recognize(path("f90")), Some(CompilerType::Flang));
386-
assert_eq!(recognizer.recognize(path("f95")), Some(CompilerType::Flang));
387-
assert_eq!(recognizer.recognize(path("f03")), Some(CompilerType::Flang));
388-
assert_eq!(recognizer.recognize(path("f08")), Some(CompilerType::Flang));
378+
assert_eq!(recognizer.recognize(path("flang-new")), Some(CompilerType::Flang));
389379

390380
// Cross-compilation variants
391-
assert_eq!(recognizer.recognize(path("arm-linux-gnueabi-gfortran")), Some(CompilerType::Flang));
381+
assert_eq!(recognizer.recognize(path("arm-linux-gnueabi-gfortran")), Some(CompilerType::Gcc));
392382

393383
// Versioned variants
394-
assert_eq!(recognizer.recognize(path("gfortran-11")), Some(CompilerType::Flang));
395-
assert_eq!(recognizer.recognize(path("gfortran11")), Some(CompilerType::Flang));
396-
assert_eq!(recognizer.recognize(path("f90-4.8")), Some(CompilerType::Flang));
384+
assert_eq!(recognizer.recognize(path("gfortran-11")), Some(CompilerType::Gcc));
385+
assert_eq!(recognizer.recognize(path("gfortran11")), Some(CompilerType::Gcc));
386+
assert_eq!(recognizer.recognize(path("f95-4.8")), Some(CompilerType::Gcc));
397387
}
398388

399389
#[test]
@@ -512,6 +502,7 @@ mod tests {
512502
assert_eq!(recognizer.recognize(path("cc1obj")), Some(CompilerType::Gcc));
513503
assert_eq!(recognizer.recognize(path("cc1objplus")), Some(CompilerType::Gcc));
514504
assert_eq!(recognizer.recognize(path("collect2")), Some(CompilerType::Gcc));
505+
assert_eq!(recognizer.recognize(path("f951")), Some(CompilerType::Gcc));
515506
assert_eq!(recognizer.recognize(path("lto1")), Some(CompilerType::Gcc));
516507

517508
// Test with full paths
@@ -566,7 +557,7 @@ mod tests {
566557
);
567558

568559
// Test Fortran pattern matching when 'as' is None
569-
assert_eq!(recognizer.recognize(path("gfortran")), Some(CompilerType::Flang));
560+
assert_eq!(recognizer.recognize(path("gfortran")), Some(CompilerType::Gcc));
570561
}
571562

572563
#[test]
@@ -618,7 +609,7 @@ mod tests {
618609
assert_eq!(recognizer.recognize(path("g++-9.3.0")), Some(CompilerType::Gcc));
619610
assert_eq!(recognizer.recognize(path("clang-15")), Some(CompilerType::Clang));
620611
assert_eq!(recognizer.recognize(path("clang-12.1")), Some(CompilerType::Clang));
621-
assert_eq!(recognizer.recognize(path("gfortran-12")), Some(CompilerType::Flang));
612+
assert_eq!(recognizer.recognize(path("gfortran-12")), Some(CompilerType::Gcc));
622613
assert_eq!(recognizer.recognize(path("ifort-2023")), Some(CompilerType::IntelFortran));
623614
assert_eq!(recognizer.recognize(path("nvcc-11.8")), Some(CompilerType::Cuda));
624615

@@ -629,7 +620,7 @@ mod tests {
629620
// Test that non-versioned compilers still work
630621
assert_eq!(recognizer.recognize(path("gcc")), Some(CompilerType::Gcc));
631622
assert_eq!(recognizer.recognize(path("clang")), Some(CompilerType::Clang));
632-
assert_eq!(recognizer.recognize(path("gfortran")), Some(CompilerType::Flang));
623+
assert_eq!(recognizer.recognize(path("gfortran")), Some(CompilerType::Gcc));
633624

634625
// Test that wrapper executables don't have version patterns (as expected)
635626
assert_eq!(recognizer.recognize(path("ccache")), Some(CompilerType::Wrapper));

bear/src/semantic/interpreters/compilers/gcc.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ impl GccInterpreter {
6363

6464
/// GCC internal executables that should be ignored
6565
/// These are implementation details of GCC's compilation process
66-
const GCC_INTERNAL_EXECUTABLES: [&str; 6] = [
66+
const GCC_INTERNAL_EXECUTABLES: [&str; 7] = [
6767
"cc1", // C compiler proper
6868
"cc1plus", // C++ compiler proper
6969
"cc1obj", // Objective-C compiler proper
7070
"cc1objplus", // Objective-C++ compiler proper
71+
"f951", // Fortran compiler proper
7172
"collect2", // Linker wrapper
7273
"lto1", // Link-time optimization pass
7374
];
@@ -1345,6 +1346,19 @@ mod tests {
13451346
panic!("Expected ignored command for collect2");
13461347
}
13471348

1349+
// Test internal fortran executable
1350+
let fortran_execution = create_execution(
1351+
"/usr/libexec/gcc/x86_64-redhat-linux/15/f951",
1352+
vec!["f951", "fortran.f90", "-mtune=generic", "-march=x86-64", "-o", "/tmp/cc6kwJ3Y.s"],
1353+
"/home/user",
1354+
);
1355+
1356+
if let Some(Command::Ignored(reason)) = interpreter.recognize(&fortran_execution) {
1357+
assert_eq!(reason, "GCC internal executable");
1358+
} else {
1359+
panic!("Expected ignored command for collect2");
1360+
}
1361+
13481362
// Test that regular gcc commands are still recognized as compilers
13491363
let gcc_execution =
13501364
create_execution("/usr/bin/gcc", vec!["gcc", "-c", "-O2", "main.c"], "/home/user");

bear/src/semantic/interpreters/matchers/source.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ static SOURCE_EXTENSIONS: std::sync::LazyLock<HashSet<&'static str>> = std::sync
2727
// Assembly
2828
"s", "S", "sx", "asm",
2929
// Fortran
30-
"f", "for", "ftn",
31-
"F", "FOR", "fpp", "FPP", "FTN",
30+
"f", "for", "fpp", "ftn",
31+
"F", "FOR", "FPP", "FTN",
3232
"f90", "f95", "f03", "f08",
3333
"F90", "F95", "F03", "F08",
3434
// go

0 commit comments

Comments
 (0)