This is an archive of the discontinued LLVM Phabricator instance.

[clang-cl,PCH] Add support for #pragma hdrstop
ClosedPublic

Authored by mikerice on Aug 28 2018, 4:56 PM.

Details

Summary

With clang-cl, when the user specifies /Yc or /Yu without a header
the compiler uses a #pragma hdrstop in the main source file to
determine the end of the PCH. If a header is specified with /Yc or
/Yu #pragma hdrstop has no effect.

The optional filename argument is not yet supported.

Diff Detail

Repository
rC Clang

Event Timeline

mikerice created this revision.Aug 28 2018, 4:56 PM
hans added a comment.Sep 4 2018, 2:16 AM

Very cool! I only have some minor comments.

Oh, and when it lands, you should probably add an update to docs/ReleaseNotes.rst about it too.

include/clang/Driver/CC1Options.td
609

should this mention the argument is supposed to be "create" or "use"?

lib/Driver/Driver.cpp
2984โ€“2985

I think this part of the comment no longer applies.

4270โ€“4273

The declaration of YcArg could still be part of the if-statement below, I think. It doesn't look like you're using it outside the if.

lib/Driver/ToolChains/Clang.cpp
1124

nit: i'd probably use a curly brace here since the statement below doesn't fit on one line. maybe that's just me though.

lib/Frontend/CompilerInvocation.cpp
2867

hmm, what if the value is not "create", but also not "use" but something else? maybe that should be diagnosed, or maybe the flag should be split into two?

lib/Lex/Pragma.cpp
904

Nice!

test/Driver/cl-pch.cpp
280

i suppose if there's a "2." comment, might as well have a comment for step 1 too. same for "/Yc with no argument and no /FP" below

mikerice updated this revision to Diff 163946.Sep 4 2018, 4:43 PM
mikerice marked 7 inline comments as done.

Thanks for the review. Updated based on comments from Hans.

mikerice added inline comments.Sep 4 2018, 4:45 PM
lib/Frontend/CompilerInvocation.cpp
2867

I am not totally happy with this but I thought one option might be a little better than two. It would be equivalent to create two options OPT_pch_through_hdrstop_create and OPT_pch_through_hdrstop_use if that seems better (or more usual) to everyone. I added a diagnostic if the value is not "create" or "use". A user should never see that though if the front end and driver as in sync.

lib/Lex/Pragma.cpp
904

I have to give Nico credit for this. It's from his patch that I based these changes.

hans added inline comments.Sep 10 2018, 1:02 AM
lib/Frontend/CompilerInvocation.cpp
2867

Thinking about it again, having two separate flags seems more common to me.

mikerice updated this revision to Diff 164698.Sep 10 2018, 10:40 AM
mikerice marked an inline comment as done.

Updated to use two options: -pch-through-header-create and -pch-through-header-use.

hans accepted this revision.Sep 11 2018, 2:37 AM

lgtm!

Please add a note to docs/ReleaseNotes.rst when landing.

This revision is now accepted and ready to land.Sep 11 2018, 2:37 AM
This revision was automatically updated to reflect the committed changes.