Skip to content

fix(compilerlib): run no job after a driver error - #268

Draft
SizzleUnrlsd wants to merge 7 commits into
mainfrom
fix/stop-after-a-driver-error
Draft

SizzleUnrlsd wants to merge 7 commits into
mainfrom
fix/stop-after-a-driver-error

Conversation

@SizzleUnrlsd

@SizzleUnrlsd SizzleUnrlsd commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When Clang's driver reports an error while it builds the compilation, compilerlib::compile still ran the jobs, and succeeded, in every mode but plain file output (#264). A compilation to memory, to a module or with --instrument now fails with the driver's error, before any job runs, as clang does.

Closes #264

Not part of 0.13.0: that release lists #264 among its known issues, so that the effect of this change on the hosts of compilerlib can be checked before they move to it. The changelog entry comes with a new Unreleased section, once 0.13.0 is released.

Behaviour changes

  • A driver error fails the compilation in every mode. In memory, to a module (compileToModule) and with --instrument, a compilation printed the error and gave its output. Plain file output already failed, through the driver's ExecuteCompilation.
  • An argument clang rejects is such an error. A compilation to memory with an option of GCC's that clang does not know, such as -fno-var-tracking-assignments, gave its IR with error: unknown argument; it now fails, as clang does. A command written for GCC whose arguments clang accepts is not affected. See Impact.
  • Unchanged: a driver warning does not fail a compilation.

Change

  • fix(compilerlib): run no job after a driver error: the modes that run the jobs themselves ask the driver's diagnostics for an error once the job plan is checked, where clang's Driver::ExecuteCompilation returns its failure, and return the driver's diagnostics.
  • test(compilerlib), six tests: with a working directory that does not exist, a compilation to memory, to bitcode in memory, to a module and an instrumented one fail with the driver's error, and give no IR, module or object; so does a compilation whose sample profile does not exist; a compilation with an argument it does not use succeeds, with the driver's warning.

Tests

macOS arm64, LLVM 20.1.2. Each command compiles a source of one function, with -S -emit-llvm:

Arguments clang 20.1.2 cc --in-mem at 6eb4646 cc --in-mem, this branch
-working-directory <missing> fails succeeds, prints the error and the IR fails
-fno-such-flag fails: unknown argument succeeds, prints the error and the IR fails
-fno-var-tracking-assignments fails: unknown argument succeeds, prints the error and the IR fails
-L<dir>, unused succeeds, with a warning succeeds, with a warning succeeds, with a warning
-Wno-such-warning succeeds, with a warning succeeds succeeds
-Werror -L<dir> fails: the warning is an error succeeds, with a warning succeeds, with a warning

The last row is a difference this pull request does not change: compilerlib does not apply -Werror to the driver's warnings.

With --instrument -fno-such-flag -c, cc wrote the object and returned 0 at 6eb4646; this branch writes none and returns 1, as plain file output does.

  • Before the fix (RED), on main at 61f88b5, five of the six new tests fail, each because the compilation succeeds:
    • FailsACompilationToMemory and FailsACompilationToBitcodeInMemory: success is true and the IR is returned;
    • FailsAnInstrumentedCompilation: success is true and the object is written;
    • FailsACompilationToAModule: success is true and the module is returned;
    • FailsACompilationWhoseProfileIsMissing: success is true;
    • LeavesACompilationWithADriverWarningAlone passes, as it must before and after.
  • With the fix (GREEN), the six pass, and no other test changes:
    • unit tests, LLVM 20.1.2: ctest -j2 315/315, the 309 of main plus the 6 new tests; the 221 unit tests of compilerlib pass in a shuffled order;
    • unit tests, LLVM 16.0.6: all 221 pass.
  • Each of the seven commits builds and passes the unit tests of compilerlib, 215 to 221.
  • clang-format 18, scripts/check-license-compliance.sh and the commit checker pass.

CI at dcb6170

  • LLVM versions run 43942175017: 15/15 jobs pass. Every test passes in each job: 318 on Windows, 315 on Linux and macOS. The six new tests pass in all 15, from LLVM 16 to LLVM 23.
  • Build run 43942175055: passes. Every test passes: 221 without the runtime, 315 with coverage, 316 with AddressSanitizer and UBSan, the six new tests among them. The Docker job is skipped, as on every pull request.
  • Other checks: clang-format, license-compliance and the commit conventions pass.

Impact

  • Which commands: only those with an argument that clang rejects. A compile command written for GCC compiles as before when clang accepts its arguments.
  • coretrace-stack-analyzer compiles the commands of a compilation database as they are, apart from their output and dependency options. With -fno-var-tracking-assignments in a command for gcc, the analyzer of perf(input): compile sources in parallel, each in its directory coretrace-stack-analyzer#272, built with compilerlib 8a99cf3, warns error: unknown argument and reports the unit: exit status 0, one function and one diagnostic. With this change, that compilation fails. The analyzer was not built with this change.
  • An adaptation of the analyzer must keep the meaning of the program it analyzes. Removing every option clang does not know is not safe in general: an option may change what the code means. What the analyzer does with such a command, remove a known harmless option or report the unit as not compiled, is its own decision, to take before it moves to a compilerlib with this change.
  • The analyzer's own check of a compile command's directory, which perf(input): compile sources in parallel, each in its directory coretrace-stack-analyzer#272 added because of In memory and instrumented, a compilation goes on after a driver error #264, is no longer needed with this change.
  • Other hosts: not known. A host that reads success gets a failure where it got an output with an error line.

When Clang's driver reports an error while it builds the compilation,
such as an unknown argument or a working directory it cannot move to,
clang runs no job: Driver::ExecuteCompilation returns a failure. Plain
file output goes through it. The other modes, which run the jobs
themselves, went on: a compilation to memory, to a module or with
--instrument printed the error and gave its output.

They now fail with the driver's diagnostics before any job runs.

Refs #264
A working directory that does not exist: the compilation fails with the
driver's error and gives no IR.

Refs #264
The compilation fails and writes no object.

Refs #264
Another error of the driver's: the profile of -fprofile-sample-use=
does not exist.

Refs #264
An argument the compilation does not use: the IR comes with the
driver's warning.

Refs #264
@SizzleUnrlsd SizzleUnrlsd added the bug Something isn't working label Nov 16, 2026
@SizzleUnrlsd SizzleUnrlsd self-assigned this Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In memory and instrumented, a compilation goes on after a driver error

1 participant