Skip to content

Commit

Permalink
Make clang report invalid target versions for all environment.
Browse files Browse the repository at this point in the history
Followup for llvm#75373

1. Make this feature not just available for android, but everyone.
2. Correct some target triples.
3. Add opencl to the environment type list.
  • Loading branch information
ZijunZhaoCCK committed Jan 19, 2024
1 parent b5daff2 commit a2e1335
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1433,10 +1433,11 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
// Check if the environment version is valid.
llvm::Triple Triple = TC.getTriple();
StringRef TripleVersionName = Triple.getEnvironmentVersionString();
StringRef TripleObjectFormat = Triple.getObjectFormatTypeName(Triple.getObjectFormat());
StringRef TripleObjectFormat =
Triple.getObjectFormatTypeName(Triple.getObjectFormat());

if (Triple.getEnvironmentVersion().empty() && TripleVersionName != ""
&& TripleVersionName != TripleObjectFormat) {
if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "" &&
TripleVersionName != TripleObjectFormat) {
Diags.Report(diag::err_drv_triple_version_invalid)
<< TripleVersionName << TC.getTripleString();
ContainsError = true;
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/TargetParser/Triple.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class Triple {
Cygnus,
CoreCLR,
Simulator, // Simulator variants of other systems, e.g., Apple's iOS
MacABI, // Mac Catalyst variant of Apple's iOS deployment target.
MacABI, // Mac Catalyst variant of Apple's iOS deployment target.

// Shader Stages
// The order of these values matters, and must be kept in sync with the
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/TargetParser/Triple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
case Callable: return "callable";
case Mesh: return "mesh";
case Amplification: return "amplification";
case OpenCL: return "opencl";
case OpenCL:
return "opencl";
case OpenHOS: return "ohos";
}

Expand Down Expand Up @@ -1220,7 +1221,8 @@ VersionTuple Triple::getEnvironmentVersion() const {
StringRef Triple::getEnvironmentVersionString() const {
StringRef EnvironmentName = getEnvironmentName();

// none is a valid environment type - it basically amounts to a freestanding environment.
// none is a valid environment type - it basically amounts to a freestanding
// environment.
if (EnvironmentName == "none")
return "";

Expand Down

0 comments on commit a2e1335

Please sign in to comment.