Skip to content

Commit 5e59a29

Browse files
committed
Adjust behaviors for review comments
Use separate DenseMap for exit behaviors Update names and usage model to avoid double negatives
1 parent b1ff52f commit 5e59a29

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed

clang/include/clang/Driver/Job.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ struct ResponseFileSupport {
105105
/// execute.
106106
class Command {
107107
public:
108-
using ErrorCodeDiagMapTy = llvm::DenseMap<int, std::pair<std::string, bool>>;
108+
using ErrorCodeDiagMapTy = llvm::DenseMap<int, std::string>;
109+
using ErrorCodeExitMapTy = llvm::DenseMap<int, bool>;
109110

110111
private:
111112
/// Source - The action which caused the creation of this job.
@@ -122,8 +123,6 @@ class Command {
122123

123124
/// The container for custom driver-set diagnostic messages that are
124125
/// produced upon particular error codes returned by the command.
125-
/// Given a custom diagnostic, also allow for logic to determine if the
126-
/// compilation should continue, even with a non-zero return code.
127126
/// In order to add such a diagnostic for an external tool, consider the
128127
/// following criteria:
129128
/// 1) Does the command's executable return different codes upon different
@@ -134,6 +133,11 @@ class Command {
134133
/// "invalid input" error can be ruled out
135134
ErrorCodeDiagMapTy ErrorCodeDiagMap;
136135

136+
/// Similar to the container for the diagnostic messages, this container
137+
/// is used to signify if the toolchain should error and exit right away
138+
/// or if we should continue compilation.
139+
ErrorCodeExitMapTy ErrorCodeExitMap;
140+
137141
/// The list of program arguments (not including the implicit first
138142
/// argument, which will be the executable).
139143
llvm::opt::ArgStringList Arguments;
@@ -198,17 +202,20 @@ class Command {
198202

199203
/// Store a custom driver diagnostic message and if the compilation should
200204
/// exit upon a particular error code returned by the command
201-
void addDiagForErrorCode(int ErrorCode, StringRef CustomDiag,
202-
bool NoExit = false);
205+
void addDiagForErrorCode(int ErrorCode, StringRef CustomDiag);
206+
207+
/// Store if the compilation should exit upon a particular error code
208+
/// returned by the command
209+
void addExitForErrorCode(int ErrorCode, bool Exit);
203210

204211
/// Get the custom driver diagnostic message for a particular error code
205212
/// if such was stored. Returns an empty string if no diagnostic message
206213
/// was found for the given error code.
207214
StringRef getDiagForErrorCode(int ErrorCode) const;
208215

209216
/// Will the tool exit when a particular error code is encountered. Returns
210-
/// false if not set (always exit)
211-
bool getWillNotExitForErrorCode(int ErrorCode) const;
217+
/// true if not set (always exit)
218+
bool getWillExitForErrorCode(int ErrorCode) const;
212219

213220
/// getSource - Return the Action which caused the creation of this job.
214221
const Action &getSource() const { return Source; }

clang/lib/Driver/Compilation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ static bool ActionFailed(const Action *A,
250250
return false;
251251

252252
for (const auto &CI : FailingCommands)
253-
if (CI.second->getWillNotExitForErrorCode(CI.first))
253+
if (!CI.second->getWillExitForErrorCode(CI.first))
254254
return false;
255255

256256
// CUDA/HIP/SYCL can have the same input source code compiled multiple times
@@ -292,7 +292,7 @@ void Compilation::ExecuteJobs(const JobList &Jobs,
292292
// Do not bail when the tool is setup to allow for continuation upon
293293
// failure.
294294
if (TheDriver.IsCLMode() &&
295-
!FailingCommand->getWillNotExitForErrorCode(Res))
295+
FailingCommand->getWillExitForErrorCode(Res))
296296
return;
297297
}
298298
}

clang/lib/Driver/Job.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,24 +158,26 @@ void Command::buildArgvForResponseFile(
158158
}
159159
}
160160

161-
void Command::addDiagForErrorCode(int ErrorCode, StringRef CustomDiag,
162-
bool NoExit) {
163-
ErrorCodeDiagMap[ErrorCode].first = CustomDiag.str();
164-
ErrorCodeDiagMap[ErrorCode].second = NoExit;
161+
void Command::addDiagForErrorCode(int ErrorCode, StringRef CustomDiag) {
162+
ErrorCodeDiagMap[ErrorCode] = CustomDiag.str();
163+
}
164+
165+
void Command::addExitForErrorCode(int ErrorCode, bool Exit) {
166+
ErrorCodeExitMap[ErrorCode] = Exit;
165167
}
166168

167169
StringRef Command::getDiagForErrorCode(int ErrorCode) const {
168170
auto ErrorCodeDiagIt = ErrorCodeDiagMap.find(ErrorCode);
169171
if (ErrorCodeDiagIt != ErrorCodeDiagMap.end())
170-
return ErrorCodeDiagIt->second.first;
172+
return ErrorCodeDiagIt->second;
171173
return StringRef();
172174
}
173175

174-
bool Command::getWillNotExitForErrorCode(int ErrorCode) const {
175-
auto ErrorCodeDiagIt = ErrorCodeDiagMap.find(ErrorCode);
176-
if (ErrorCodeDiagIt != ErrorCodeDiagMap.end())
177-
return ErrorCodeDiagIt->second.second;
178-
return false;
176+
bool Command::getWillExitForErrorCode(int ErrorCode) const {
177+
auto ErrorCodeExitIt = ErrorCodeExitMap.find(ErrorCode);
178+
if (ErrorCodeExitIt != ErrorCodeExitMap.end())
179+
return ErrorCodeExitIt->second;
180+
return true;
179181
}
180182

181183
/// Rewrite relative include-like flag paths to absolute ones.

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ static void addFPGATimingDiagnostic(std::unique_ptr<Command> &Cmd,
8989
"and may produce functional errors if used. Refer to the Intel oneAPI "
9090
"DPC++ FPGA Optimization Guide section on Timing Failures for more "
9191
"information.");
92-
Cmd->addDiagForErrorCode(/*ErrorCode*/ 42, Msg, true);
92+
Cmd->addDiagForErrorCode(/*ErrorCode*/ 42, Msg);
93+
Cmd->addExitForErrorCode(/*ErrorCode*/ 42, false);
9394
}
9495

9596
void SYCL::constructLLVMForeachCommand(Compilation &C, const JobAction &JA,

0 commit comments

Comments
 (0)