mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
New assertions support
This adds three new assertion macros: * `ASSERT` - always compiled in, always checked * `CONDITIONAL_ASSERT` - always compiled in, checked whenever the `-compiler-assertions` flag is provided * `DEBUG_ASSERT` - only compiled into debug builds, always checked when compiled in (functionally the same as Standard C `assert`) The new `-compiler-assertions` flag is recognized by both `swift-frontend` and `swiftc`. The goal is to eventually replace every use of `assert` in the compiler with one of the above: * Most assertions will use `ASSERT` (most assertions should always be present and checked, even in release builds) * Expensive assertions can use `CONDITIONAL_ASSERT` to be suppressed by default * A few very expensive and/or brittle assertions can use `DEBUG_ASSERT` to be compiled out of release builds This should: * Improve quality by catching errors earlier, * Accelerate compiler triage and debugging by providing more accurate crash dumps by default, and * Allow compiler engineers and end users alike to add `-compiler-assertions` to get more accurate failure diagnostics with any compiler
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "ArgsToFrontendOptionsConverter.h"
|
||||
#include "swift/AST/DiagnosticsFrontend.h"
|
||||
#include "swift/Basic/Assertions.h"
|
||||
#include "swift/Basic/Feature.h"
|
||||
#include "swift/Basic/Platform.h"
|
||||
#include "swift/Option/Options.h"
|
||||
@@ -328,6 +329,13 @@ bool CompilerInvocation::setModuleAliasMap(std::vector<std::string> args,
|
||||
return ModuleAliasesConverter::computeModuleAliases(args, FrontendOpts, diags);
|
||||
}
|
||||
|
||||
static void ParseAssertionArgs(ArgList &args) {
|
||||
using namespace options;
|
||||
if (args.hasArg(OPT_compiler_assertions)) {
|
||||
CONDITIONAL_ASSERT_Global_enable_flag = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static bool ParseFrontendArgs(
|
||||
FrontendOptions &opts, ArgList &args, DiagnosticEngine &diags,
|
||||
SmallVectorImpl<std::unique_ptr<llvm::MemoryBuffer>> *buffers) {
|
||||
@@ -3392,6 +3400,8 @@ bool CompilerInvocation::parseArgs(
|
||||
return true;
|
||||
}
|
||||
|
||||
ParseAssertionArgs(ParsedArgs);
|
||||
|
||||
if (ParseLangArgs(LangOpts, ParsedArgs, Diags, FrontendOpts)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user