Skip to content

Commit e6d3e06

Browse files
Make the major _3CInterface methods return false if a tool execution
fails. It's unclear whether (1) there are still more operations in these methods that can fail and would merit an early return and (2) these early returns could cause problems for callers such as clangd3c that want to recover. But for now, adding these early returns is better than the status quo, and the only caller we support is the 3c tool, which just exits when one of these methods returns false. This exposed a problem with the partial_checked_arr test: it ran 3c on a lit temporary file named partial_checked_arr.c.tmp, and that file extension seems to cause 3c to spew errors. Previously 3c nevertheless exited 0 and the test carried on; now 3c would exit 1. Work around this by using -output-postfix like many of our other tests. This may not be the approach we want in the long term, but we don't have the new approach ready yet.
1 parent 679d3b5 commit e6d3e06

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

clang/lib/3C/3C.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,11 @@ bool _3CInterface::buildInitialConstraints() {
246246
std::unique_ptr<ToolAction> ConstraintTool = newFrontendActionFactoryA<
247247
GenericAction<ConstraintBuilderConsumer, ProgramInfo>>(GlobalProgramInfo);
248248

249-
if (ConstraintTool)
250-
Tool.run(ConstraintTool.get());
251-
else
249+
if (ConstraintTool) {
250+
int ToolExitCode = Tool.run(ConstraintTool.get());
251+
if (ToolExitCode != 0)
252+
return false;
253+
} else
252254
llvm_unreachable("No action");
253255

254256
if (!GlobalProgramInfo.link()) {
@@ -297,9 +299,11 @@ bool _3CInterface::solveConstraints(bool ComputeInterimState) {
297299
std::unique_ptr<ToolAction> ABInfTool = newFrontendActionFactoryA<
298300
GenericAction<AllocBasedBoundsInference, ProgramInfo>>(
299301
GlobalProgramInfo);
300-
if (ABInfTool)
301-
Tool.run(ABInfTool.get());
302-
else
302+
if (ABInfTool) {
303+
int ToolExitCode = Tool.run(ABInfTool.get());
304+
if (ToolExitCode != 0)
305+
return false;
306+
} else
303307
llvm_unreachable("No Action");
304308

305309
// Propagate the information from allocator bounds.
@@ -310,9 +314,11 @@ bool _3CInterface::solveConstraints(bool ComputeInterimState) {
310314
// after constraint solving but before rewriting.
311315
std::unique_ptr<ToolAction> IMTool = newFrontendActionFactoryA<
312316
GenericAction<IntermediateToolHook, ProgramInfo>>(GlobalProgramInfo);
313-
if (IMTool)
314-
Tool.run(IMTool.get());
315-
else
317+
if (IMTool) {
318+
int ToolExitCode = Tool.run(IMTool.get());
319+
if (ToolExitCode != 0)
320+
return false;
321+
} else
316322
llvm_unreachable("No Action");
317323

318324
if (AllTypes) {
@@ -364,8 +370,11 @@ bool _3CInterface::writeConvertedFileToDisk(const std::string &FilePath) {
364370
newFrontendActionFactoryA<RewriteAction<RewriteConsumer, ProgramInfo>>(
365371
GlobalProgramInfo);
366372

367-
if (RewriteTool)
368-
Tool.run(RewriteTool.get());
373+
if (RewriteTool) {
374+
int ToolExitCode = Tool.run(RewriteTool.get());
375+
if (ToolExitCode != 0)
376+
return false;
377+
}
369378
return true;
370379
}
371380
return false;
@@ -380,9 +389,11 @@ bool _3CInterface::writeAllConvertedFilesToDisk() {
380389
std::unique_ptr<ToolAction> RewriteTool =
381390
newFrontendActionFactoryA<RewriteAction<RewriteConsumer, ProgramInfo>>(
382391
GlobalProgramInfo);
383-
if (RewriteTool)
384-
Tool.run(RewriteTool.get());
385-
else
392+
if (RewriteTool) {
393+
int ToolExitCode = Tool.run(RewriteTool.get());
394+
if (ToolExitCode != 0)
395+
return false;
396+
} else
386397
llvm_unreachable("No action");
387398

388399
return true;

clang/test/3C/partial_checked_arr.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
// RUN: 3c -addcr -alltypes %s | %clang -c -f3c-tool -fcheckedc-extension -x c -o %t1.unused -
33
// RUN: 3c -addcr %s | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s
44
// RUN: 3c -addcr %s | %clang -c -f3c-tool -fcheckedc-extension -x c -o %t2.unused -
5-
// RUN: 3c -alltypes %s > %t
6-
// RUN: 3c -alltypes %t | count 0
5+
// RUN: 3c -alltypes -output-postfix=checked %s
6+
// RUN: 3c -alltypes %S/partial_checked_arr.checked.c -- | count 0
7+
// RUN: rm %S/partial_checked_arr.checked.c
78

89
int strcmp(const char *src1 : itype(_Nt_array_ptr<const char>),
910
const char *src2 : itype(_Nt_array_ptr<const char>));

0 commit comments

Comments
 (0)