Skip to content

Commit 789d38e

Browse files
committed
Control #file behavior with a command line option
1 parent e5b582f commit 789d38e

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ namespace swift {
9494
/// when using RequireExplicitAvailability.
9595
std::string RequireExplicitAvailabilityTarget;
9696

97+
/// If true, '#file' evaluates to the full path rather than a
98+
/// human-readable string.
99+
bool MagicFileIdentifierEvaluatesToPath = false;
100+
97101
///
98102
/// Support for alternate usage modes
99103
///

include/swift/Option/Options.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,14 @@ def output_file_map_EQ : Joined<["-"], "output-file-map=">,
267267
Flags<[NoInteractiveOption, ArgumentIsPath]>,
268268
Alias<output_file_map>;
269269

270+
def pound_file : Separate<["-"], "pound-file">,
271+
Flags<[FrontendOption]>,
272+
HelpText<"Specifies whether '#file' evaluates to a full path or a compact human-readable string">,
273+
MetaVarName<"compact|path">;
274+
def pound_file_EQ : Joined<["-"], "pound-file=">,
275+
Flags<[FrontendOption]>,
276+
Alias<pound_file>;
277+
270278
def save_temps : Flag<["-"], "save-temps">,
271279
Flags<[NoInteractiveOption,DoesNotAffectIncrementalBuild]>,
272280
HelpText<"Save intermediate compilation results">;

lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ static void addCommonFrontendArgs(const ToolChain &TC, const OutputInfo &OI,
238238
inputArgs.AddLastArg(arguments, options::OPT_enable_astscope_lookup);
239239
inputArgs.AddLastArg(arguments, options::OPT_disable_astscope_lookup);
240240
inputArgs.AddLastArg(arguments, options::OPT_disable_parser_lookup);
241+
inputArgs.AddLastArg(arguments, options::OPT_pound_file);
241242

242243
// Pass on any build config options
243244
inputArgs.AddAllArgs(arguments, options::OPT_D);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,17 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
453453
Opts.OptimizationRemarkMissedPattern =
454454
generateOptimizationRemarkRegex(Diags, Args, A);
455455

456+
if (Arg *A = Args.getLastArg(OPT_pound_file)) {
457+
StringRef value = A->getValue();
458+
if (value == "path")
459+
Opts.MagicFileIdentifierEvaluatesToPath = true;
460+
else if (value == "compact")
461+
Opts.MagicFileIdentifierEvaluatesToPath = false;
462+
else
463+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
464+
A->getSpelling(), value);
465+
}
466+
456467
llvm::Triple Target = Opts.Target;
457468
StringRef TargetArg;
458469
if (const Arg *A = Args.getLastArg(OPT_target)) {

lib/SILGen/SILGenApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4881,7 +4881,7 @@ static std::string getMagicFileString(SILGenFunction &SGF, SourceLoc loc) {
48814881
return "";
48824882

48834883
auto path = SGF.getASTContext().SourceMgr.getDisplayNameForLoc(loc);
4884-
if (false /* FIXME: Add a command line flag for this */)
4884+
if (SGF.getASTContext().LangOpts.MagicFileIdentifierEvaluatesToPath)
48854885
return path;
48864886

48874887
auto value = llvm::sys::path::filename(path).str();

0 commit comments

Comments
 (0)