Skip to content

[clang][Driver] Add flag for setting SkipFunctionBodies #100135

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
Jul 25, 2024

Conversation

kadircet
Copy link
Member

This is an option set by certain tools (clangd and ASTUnit). Sometimes
there are crashes in clang unique to this configuration and it's really
hard to provide reproducers without invoking the tool.

@kadircet kadircet requested a review from ilya-biryukov July 23, 2024 14:48
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jul 23, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 23, 2024

@llvm/pr-subscribers-clang

Author: kadir çetinkaya (kadircet)

Changes

This is an option set by certain tools (clangd and ASTUnit). Sometimes
there are crashes in clang unique to this configuration and it's really
hard to provide reproducers without invoking the tool.


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

2 Files Affected:

  • (modified) clang/include/clang/Driver/Options.td (+3)
  • (added) clang/test/Frontend/skip-function-bodies.cc (+8)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 69269cf7537b0..130b2bd68c8b4 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -7525,6 +7525,9 @@ def code_completion_brief_comments : Flag<["-"], "code-completion-brief-comments
 def code_completion_with_fixits : Flag<["-"], "code-completion-with-fixits">,
   HelpText<"Include code completion results which require small fix-its.">,
   MarshallingInfoFlag<FrontendOpts<"CodeCompleteOpts.IncludeFixIts">>;
+def skip_function_bodies : Flag<["-"], "skip-function-bodies">,
+  HelpText<"Skip function bodies when possible">,
+  MarshallingInfoFlag<FrontendOpts<"SkipFunctionBodies">>;
 def disable_free : Flag<["-"], "disable-free">,
   HelpText<"Disable freeing of memory on exit">,
   MarshallingInfoFlag<FrontendOpts<"DisableFree">>;
diff --git a/clang/test/Frontend/skip-function-bodies.cc b/clang/test/Frontend/skip-function-bodies.cc
new file mode 100644
index 0000000000000..dd5ad21424bac
--- /dev/null
+++ b/clang/test/Frontend/skip-function-bodies.cc
@@ -0,0 +1,8 @@
+// Trivial check to ensure skip-function-bodies flag is propagated.
+//
+// RUN: %clang_cc1 -verify -skip-function-bodies -pedantic-errors %s
+
+int f() {
+  // normally this should emit some diags, but we're skipping it!
+  this is garbage; 
+}

@ilya-biryukov
Copy link
Contributor

I am generally supportive of the idea to expose this for more easily reproducing bugs in source tools, and clangd, in particular.
However, I think it'd be useful to make sure the Clang maintainers are on board.
@cor3ntin, @AaronBallman do you have any objection to exposing this option?

Copy link
Contributor

@ilya-biryukov ilya-biryukov left a comment

Choose a reason for hiding this comment

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

Let's give other folks a chance to reply before landing this.

@AaronBallman AaronBallman requested a review from MaskRay July 23, 2024 15:15
Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

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

My initial thinking was that this doesn't scale particularly well as there may be other options we want to also set at the same time to help produce a reproducer. But after looking through the existing options, I don't really see others that don't already have some form of option. But I'll still ask the question: would it make sense to name this -helpful-reproducers or something more generic so we don't feel tempted to expose even more internal options this way?

That said, so long as this is a -cc1-only option, it seems reasonable to me.

@MaskRay
Copy link
Member

MaskRay commented Jul 23, 2024

The subject could be clarified: "Add cc1 option for ..." so that readers are clear this is not a driver option.

This is an option set by certain tools (clangd and ASTUnit). Sometimes
there are crashes in clang unique to this configuration and it's really
hard to provide reproducers without invoking the tool.
@kadircet kadircet force-pushed the flag_skip_function_bodies branch from 5c7564d to 884a272 Compare July 24, 2024 12:02
@kadircet
Copy link
Member Author

That said, so long as this is a -cc1-only option, it seems reasonable to m

this is a cc1-only option. added test, updated the commit message.

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

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

LGTM


// Make sure we only accept it as a cc1 arg.
// RUN: not %clang -skip-function-bodies %s 2>&1 | FileCheck %s
// CHECK: clang: error: unknown argument '-skip-function-bodies'; did you mean '-Xclang -skip-function-bodies'?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yay for a diagnostic, boo for it suggesting -Xclang in this instance, but I think we can live with it.

@ilya-biryukov
Copy link
Contributor

But I'll still ask the question: would it make sense to name this -helpful-reproducers or something more generic so we don't feel tempted to expose even more internal options this way?

This is tricky as some issues reproduce only when we skip function bodies and sometimes when we don't. Sometimes we need a PCM that skips function bodies and another file consuming it that does not (this is a normal operation mode of Clangd).
So even this particular flag does not bundle well with any other as we might need to set it independently of everything else.

+1 to Fangrui's suggestion to mention this is a -cc1 flag in the subject line when committing this.
Otherwise, LGTM.

@kadircet kadircet merged commit 456c512 into llvm:main Jul 25, 2024
7 checks passed
@kadircet kadircet deleted the flag_skip_function_bodies branch July 25, 2024 09:27
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
Summary:
This is an option set by certain tools (clangd and ASTUnit). Sometimes
there are crashes in clang, unique to this configuration and it's really
hard to provide reproducers without invoking the tool.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60250597
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants