Skip to content

Commit

Permalink
[PS4/PS5] Tidy up driver warnings finding the SDK
Browse files Browse the repository at this point in the history
Instead of warning possibly up to 3 times about the same problem,
warn only about the actual missing directories.
  • Loading branch information
pogo59 committed Jul 17, 2023
1 parent 610fc5c commit ba9a7f7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 31 deletions.
8 changes: 2 additions & 6 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -575,17 +575,13 @@ def err_drv_unsupported_fpatchable_function_entry_argument : Error<
"the second argument of '-fpatchable-function-entry' must be smaller than the first argument">;

def warn_drv_unable_to_find_directory_expected : Warning<
"unable to find %0 directory, expected to be in '%1'">,
InGroup<InvalidOrNonExistentDirectory>, DefaultIgnore;
"unable to find %0 directory, expected to be in '%1' found via %2">,
InGroup<InvalidOrNonExistentDirectory>;

def warn_drv_ps_force_pic : Warning<
"option '%0' was ignored by the %1 toolchain, using '-fPIC'">,
InGroup<OptionIgnored>;

def warn_drv_ps_sdk_dir : Warning<
"environment variable '%0' is set, but points to invalid or nonexistent directory '%1'">,
InGroup<InvalidOrNonExistentDirectory>;

def err_drv_defsym_invalid_format : Error<"defsym must be of the form: sym=value: %0">;
def err_drv_defsym_invalid_symval : Error<"value is not an integer: %0">;
def warn_drv_msvc_not_found : Warning<
Expand Down
35 changes: 14 additions & 21 deletions clang/lib/Driver/ToolChains/PS4CPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,30 +256,23 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const llvm::Triple &Triple,
D.Diag(clang::diag::err_drv_unsupported_opt_for_target)
<< "-static" << Platform;

// Determine where to find the PS4/PS5 libraries. We use the EnvVar
// if it exists; otherwise use the driver's installation path, which
// should be <SDK_DIR>/host_tools/bin.

SmallString<512> SDKDir;
if (const char *EnvValue = getenv(EnvVar)) {
if (!llvm::sys::fs::exists(EnvValue))
D.Diag(clang::diag::warn_drv_ps_sdk_dir) << EnvVar << EnvValue;
SDKDir = EnvValue;
} else {
SDKDir = D.Dir;
llvm::sys::path::append(SDKDir, "/../../");
}

// By default, the driver won't report a warning if it can't find the
// SDK include or lib directories. This behavior could be changed if
// -Weverything or -Winvalid-or-nonexistent-directory options are passed.
// Determine where to find the PS4/PS5 libraries.
// If -isysroot was passed, use that as the SDK base path.
// If not, we use the EnvVar if it exists; otherwise use the driver's
// installation path, which should be <SDK_DIR>/host_tools/bin.
SmallString<80> Whence;
if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
SDKRootDir = A->getValue();
if (!llvm::sys::fs::exists(SDKRootDir))
D.Diag(clang::diag::warn_missing_sysroot) << SDKRootDir;
} else
SDKRootDir = std::string(SDKDir.str());
Whence = A->getSpelling();
} else if (const char *EnvValue = getenv(EnvVar)) {
SDKRootDir = EnvValue;
Whence = { "environment variable '", EnvVar, "'" };
} else {
SDKRootDir = D.Dir + "/../../";
Whence = "compiler's location";
}

SmallString<512> SDKIncludeDir(SDKRootDir);
llvm::sys::path::append(SDKIncludeDir, "target/include");
Expand All @@ -289,7 +282,7 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const llvm::Triple &Triple,
!Args.hasArg(options::OPT__sysroot_EQ) &&
!llvm::sys::fs::exists(SDKIncludeDir)) {
D.Diag(clang::diag::warn_drv_unable_to_find_directory_expected)
<< Twine(Platform, " system headers").str() << SDKIncludeDir;
<< Twine(Platform, " system headers").str() << SDKIncludeDir << Whence;
}

SmallString<512> SDKLibDir(SDKRootDir);
Expand All @@ -301,7 +294,7 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const llvm::Triple &Triple,
!Args.hasArg(options::OPT_emit_ast) &&
!llvm::sys::fs::exists(SDKLibDir)) {
D.Diag(clang::diag::warn_drv_unable_to_find_directory_expected)
<< Twine(Platform, " system libraries").str() << SDKLibDir;
<< Twine(Platform, " system libraries").str() << SDKLibDir << Whence;
return;
}
getFilePaths().push_back(std::string(SDKLibDir.str()));
Expand Down
6 changes: 3 additions & 3 deletions clang/test/Driver/frame-pointer-elim.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// KEEP-ALL-NOT: warning:
// KEEP-ALL-NOT: warning: argument unused
// KEEP-ALL: "-mframe-pointer=all"
// KEEP-NON-LEAF-NOT: warning:
// KEEP-NON-LEAF-NOT: warning: argument unused
// KEEP-NON-LEAF: "-mframe-pointer=non-leaf"
// KEEP-NONE-NOT: warning:
// KEEP-NONE-NOT: warning: argument unused
// KEEP-NONE: "-mframe-pointer=none"

// On Linux x86, omit frame pointer when optimization is enabled.
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/ps4-ps5-visibility-dllstorageclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
// REDEFINE: --implicit-check-not=-fvisibility-nodllstorageclass \
// REDEFINE: --implicit-check-not=-fvisibility-externs-dllimport \
// REDEFINE: --implicit-check-not=-fvisibility-externs-nodllstorageclass \
// REDEFINE: --implicit-check-not=warning:
// REDEFINE: --implicit-check-not="warning: argument unused"
// REDEFINE: %{triple} = x86_64-scei-ps4
// RUN: %{run}
// REDEFINE: %{triple} = x86_64-sie-ps5
Expand Down

0 comments on commit ba9a7f7

Please sign in to comment.