Skip to content

[clang][modules][deps]Remove -F option from test for clang-scan-deps #141614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025

Conversation

jamieschmeiser
Copy link
Contributor

Remove the redundant -F option from test because not all platforms support -F, which is a g++ extension. The option is unnecessary because all files in the test have paths specified.

Remove the redundant -F option from test because not all platforms support -F,
which is a g++ extension.  The option is unnecessary because
all files in the test have paths specified.
@jamieschmeiser jamieschmeiser self-assigned this May 27, 2025
@jamieschmeiser jamieschmeiser added clang Clang issues not falling into any other category clang:modules C++20 modules and Clang Header Modules labels May 27, 2025
@llvmbot
Copy link
Member

llvmbot commented May 27, 2025

@llvm/pr-subscribers-clang-modules

@llvm/pr-subscribers-clang

Author: Jamie Schmeiser (jamieschmeiser)

Changes

Remove the redundant -F option from test because not all platforms support -F, which is a g++ extension. The option is unnecessary because all files in the test have paths specified.


Full diff: https://github.com/llvm/llvm-project/pull/141614.diff

1 Files Affected:

  • (modified) clang/test/ClangScanDeps/modules-pch-common-stale.c (+4-4)
diff --git a/clang/test/ClangScanDeps/modules-pch-common-stale.c b/clang/test/ClangScanDeps/modules-pch-common-stale.c
index 100124d9ad0b0..72a4dc949b0f5 100644
--- a/clang/test/ClangScanDeps/modules-pch-common-stale.c
+++ b/clang/test/ClangScanDeps/modules-pch-common-stale.c
@@ -27,7 +27,7 @@ module mod_tu_extra { header "mod_tu_extra.h" }
 
 // Clean: scan the PCH.
 // RUN: clang-scan-deps -format experimental-full -o %t/deps_pch_clean.json -- \
-// RUN:     %clang -x c-header %t/prefix.h -o %t/prefix.h.pch -F %t \
+// RUN:     %clang -x c-header %t/prefix.h -o %t/prefix.h.pch \
 // RUN:     -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache
 
 // Clean: build the PCH.
@@ -38,7 +38,7 @@ module mod_tu_extra { header "mod_tu_extra.h" }
 
 // Clean: scan the TU.
 // RUN: clang-scan-deps -format experimental-full -o %t/deps_tu_clean.json -- \
-// RUN:     %clang -c %t/tu.c -o %t/tu.o -include %t/prefix.h -F %t \
+// RUN:     %clang -c %t/tu.c -o %t/tu.o -include %t/prefix.h \
 // RUN:     -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache
 // RUN: cat %t/deps_tu_clean.json | sed 's:\\\\\?:/:g' | FileCheck %s --check-prefix=CHECK-TU-CLEAN -DPREFIX=%/t
 // CHECK-TU-CLEAN:      {
@@ -94,7 +94,7 @@ module mod_tu_extra { header "mod_tu_extra.h" }
 
 // Incremental: scan the PCH.
 // RUN: clang-scan-deps -format experimental-full -o %t/deps_pch_incremental.json -- \
-// RUN:     %clang -x c-header %t/prefix.h -o %t/prefix.h.pch -F %t \
+// RUN:     %clang -x c-header %t/prefix.h -o %t/prefix.h.pch \
 // RUN:     -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache
 
 // Incremental: build the PCH.
@@ -107,7 +107,7 @@ module mod_tu_extra { header "mod_tu_extra.h" }
 //              TU that depend on modules imported from the PCH and discover the
 //              new dependency on 'mod_tu_extra'.
 // RUN: clang-scan-deps -format experimental-full -o %t/deps_tu_incremental.json -- \
-// RUN:     %clang -c %t/tu.c -o %t/tu.o -include %t/prefix.h -F %t \
+// RUN:     %clang -c %t/tu.c -o %t/tu.o -include %t/prefix.h \
 // RUN:     -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache
 // RUN: cat %t/deps_tu_incremental.json | sed 's:\\\\\?:/:g' | FileCheck %s --check-prefix=CHECK-TU-INCREMENTAL -DPREFIX=%/t
 // CHECK-TU-INCREMENTAL:      {

Copy link
Member

@cyndyishida cyndyishida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

not all platforms support -F, which is a g++ extension.

It indeed looks unnecessary for this test, but what is the correct way to enable support for -F in clang tests? I would actually expect it to show up often in our tests as it's a common option for Darwin targets, but doesn't need to be strictly tied to a platform.

@jamieschmeiser jamieschmeiser merged commit 63385e7 into main May 28, 2025
16 of 17 checks passed
@jamieschmeiser jamieschmeiser deleted the users/jamieschmeiser/remove_F_option branch May 28, 2025 16:30
@cyndyishida
Copy link
Member

what is the correct way to enable support for -F in clang tests?

@jamieschmeiser can you please answer my question?

@jamieschmeiser
Copy link
Contributor Author

I am looking into what is done elsewhere. Not relying on -F, as is now the case here, is one way (which doesn't really answer your question...)

@jamieschmeiser
Copy link
Contributor Author

jamieschmeiser commented May 28, 2025

@cyndyishida The correct way to enable support for -F is to specify --target=<some darwin target>, eg --target=x86_64-apple-macos. According to https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html, -F is a darwin extension in g++ so it only makes sense for darwin in clang. Currently, it is quietly accepted and ignored by most other targets. Another way that -F can be safely used is when preprocessing only (-fsyntax-only -cc1) or when just checking the command line (-###)

So, if you wish to do more than just check preprocess or check options, you should specify a darwin target.

@cyndyishida
Copy link
Member

@jamieschmeiser I apologize if this is obvious, but is it a requirement that clang options follow the same conventions as gcc? If so, where is that documented?

@jamieschmeiser
Copy link
Contributor Author

@cyndyishida From https://clang.llvm.org/compatibility.html:
Clang strives to both conform to current language standards (up to C11 and C++11) and also to implement many widely-used extensions available in other compilers, so that most correct code will "just work" when compiled with Clang. However, Clang is more strict than other popular compilers, and may reject incorrect code that other compilers allow.
I suspect that when it comes to extentions, each is considered on a case-by-case basis but I think that, in general, Clang tries to maintain option compatibility with gcc/g++. It aids in portability between compilers and platforms which may not support one or the other compiler. Particular vendors/platforms, however, may, or may not, support various gnu extensions or have conflicting options in their particular versions of Clang or in their legacy compilers (eg, earlier non-Clang-based compilers). I think that, in general, silently ignoring options that are not supported is a disservice to the user in that it misleads them into thinking that some functionality is there when it is not. -F is a darwin specific option in g++ so unless a target platform chooses to also support this option, it should be flagged as an error. I plan to introduce code in the future that will flag -F as an error on non-darwin targets for this reason. It remains to be seen through the reviews whether the error becomes general for non-darwin targets or specific to particular target platforms. I will add you as a reviewer when I post the PR, if you wish.

@cyndyishida
Copy link
Member

I think that, in general, silently ignoring options that are not supported is a disservice to the user in that it misleads them into thinking that some functionality is there when it is not.

-F is a darwin specific option in g++ so unless a target platform chooses to also support this option, it should be flagged as an error. I plan to introduce code in the future that will flag -F as an error on non-darwin targets for this reason.

@jamieschmeiser This is where I am confused. As far as I can tell, the clang support for respecting -F as a search path is not specific to darwin targets (I did a simple test using -target powerpc64-unknown-linux-gnu and a compilation that would fail without the search path option provided), so making it an error would remove preexisting functionality. And it's not obvious to me that it is valuable to remove such functionality to be more compatible with gcc.

@jamieschmeiser
Copy link
Contributor Author

Our legacy products had different functionality for -F than the current Clang -F functionality. See https://www.ibm.com/docs/en/xl-c-and-cpp-aix/16.1.0?topic=ixcod-f, in particular the note that states that this functionality is different from GCC -F (and therefore different from Clang functionality). Our current offering does not support -F (see https://www.ibm.com/docs/en/openxl-c-and-cpp-aix/17.1.3?topic=guide-compiler-options) and an error is produced. Note that this is for AIX which is different from Linux on Power.
The handling of -F may be considered controversial since it is supported as a g++ platform specific extension and this is why I indicated that the reviews would indicate whether my future PR regarding this would determine whether this error will be a general error for non-darwin targets or specific to certain target platforms. Either way, -F is not universally supported and may cause problems in the future. (Of course, there is the possibility that the community rejects either option regarding an error but I'll deal with that if it materializes...). -F is not germane to these lit tests since they are not specifically for testing the functionality of -F and should therefore be avoided if possible or restricted to those target platforms that support it.

sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
…lvm#141614)

Remove the redundant -F option from test because not all platforms
support -F, which is a g++ extension. The option is unnecessary because
all files in the test have paths specified.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants