Disable asserts, avoid line numbers in runtime checks. (#2216)
* Disable asserts, avoid line numbers in runtime checks. * Rework assertion enabling. * Review feedback.
This commit is contained in:
+14
-6
@@ -385,6 +385,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
|
|
||||||
BitcodeEmbedding.processModule(context.llvm)
|
BitcodeEmbedding.processModule(context.llvm)
|
||||||
|
|
||||||
|
appendDebugSelector()
|
||||||
appendLlvmUsed("llvm.used", context.llvm.usedFunctions + context.llvm.usedGlobals)
|
appendLlvmUsed("llvm.used", context.llvm.usedFunctions + context.llvm.usedGlobals)
|
||||||
appendLlvmUsed("llvm.compiler.used", context.llvm.compilerUsedGlobals)
|
appendLlvmUsed("llvm.compiler.used", context.llvm.compilerUsedGlobals)
|
||||||
appendStaticInitializers()
|
appendStaticInitializers()
|
||||||
@@ -2626,14 +2627,21 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
private fun appendLlvmUsed(name: String, args: List<LLVMValueRef>) {
|
private fun appendLlvmUsed(name: String, args: List<LLVMValueRef>) {
|
||||||
if (args.isEmpty()) return
|
if (args.isEmpty()) return
|
||||||
|
|
||||||
memScoped {
|
val argsCasted = args.map { it -> constPointer(it).bitcast(int8TypePtr) }
|
||||||
val argsCasted = args.map { it -> constPointer(it).bitcast(int8TypePtr) }
|
val llvmUsedGlobal =
|
||||||
val llvmUsedGlobal =
|
|
||||||
context.llvm.staticData.placeGlobalArray(name, int8TypePtr, argsCasted)
|
context.llvm.staticData.placeGlobalArray(name, int8TypePtr, argsCasted)
|
||||||
|
|
||||||
LLVMSetLinkage(llvmUsedGlobal.llvmGlobal, LLVMLinkage.LLVMAppendingLinkage)
|
LLVMSetLinkage(llvmUsedGlobal.llvmGlobal, LLVMLinkage.LLVMAppendingLinkage)
|
||||||
LLVMSetSection(llvmUsedGlobal.llvmGlobal, "llvm.metadata")
|
LLVMSetSection(llvmUsedGlobal.llvmGlobal, "llvm.metadata")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun appendDebugSelector() {
|
||||||
|
if (!context.config.produce.isNativeBinary) return
|
||||||
|
val llvmDebugSelector =
|
||||||
|
context.llvm.staticData.placeGlobal("KonanNeedDebugInfo",
|
||||||
|
Int32(if (context.shouldContainDebugInfo()) 1 else 0))
|
||||||
|
llvmDebugSelector.setConstant(true)
|
||||||
|
llvmDebugSelector.setLinkage(LLVMLinkage.LLVMExternalLinkage)
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|||||||
@@ -20,7 +20,10 @@
|
|||||||
void RuntimeAssertFailed(const char* location, const char* message) {
|
void RuntimeAssertFailed(const char* location, const char* message) {
|
||||||
// TODO: produce stacktrace and such.
|
// TODO: produce stacktrace and such.
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
konan::snprintf(buf, sizeof(buf), "%s: runtime assert: %s\n", location, message);
|
if (location != nullptr)
|
||||||
|
konan::snprintf(buf, sizeof(buf), "%s: runtime assert: %s\n", location, message);
|
||||||
|
else
|
||||||
|
konan::snprintf(buf, sizeof(buf), "runtime assert: %s\n", message);
|
||||||
konan::consoleErrorUtf8(buf, konan::strnlen(buf, sizeof(buf)));
|
konan::consoleErrorUtf8(buf, konan::strnlen(buf, sizeof(buf)));
|
||||||
konan::abort();
|
konan::abort();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,21 +27,25 @@
|
|||||||
|
|
||||||
RUNTIME_NORETURN void RuntimeAssertFailed(const char* location, const char* message);
|
RUNTIME_NORETURN void RuntimeAssertFailed(const char* location, const char* message);
|
||||||
|
|
||||||
|
// During codegeneration we set this constant to 1 or 0 to allow bitcode optimizer
|
||||||
|
// to get rid of code behind condition.
|
||||||
|
extern "C" const int KonanNeedDebugInfo;
|
||||||
|
|
||||||
#if KONAN_ENABLE_ASSERT
|
#if KONAN_ENABLE_ASSERT
|
||||||
// Use RuntimeAssert() in internal state checks, which could be ignored in production.
|
// Use RuntimeAssert() in internal state checks, which could be ignored in production.
|
||||||
#define RuntimeAssert(condition, message) \
|
#define RuntimeAssert(condition, message) \
|
||||||
if (!(condition)) { \
|
if (KonanNeedDebugInfo && (!(condition))) { \
|
||||||
RuntimeAssertFailed( __FILE__ ":" TOSTRING(__LINE__), message); \
|
RuntimeAssertFailed( __FILE__ ":" TOSTRING(__LINE__), message); \
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define RuntimeAssert(condition, message)
|
#define RuntimeAssert(condition, message)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Use RuntimeCheck() in runtime checks that could fail due to external condition and shall lead
|
// Use RuntimeCheck() in runtime checks that could fail due to external condition and shall lead
|
||||||
// to program termination. Never compiled out.
|
// to program termination. Never compiled out.
|
||||||
#define RuntimeCheck(condition, message) \
|
#define RuntimeCheck(condition, message) \
|
||||||
if (!(condition)) { \
|
if (!(condition)) { \
|
||||||
RuntimeAssertFailed( __FILE__ ":" TOSTRING(__LINE__), message); \
|
RuntimeAssertFailed(nullptr, message); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // RUNTIME_ASSERT_H
|
#endif // RUNTIME_ASSERT_H
|
||||||
|
|||||||
Reference in New Issue
Block a user