[clang] [compiler-rt] [ubsan] Display correct runtime messages for negative _BitInt (PR #96240)

via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 20 06:57:20 PDT 2024


================
@@ -3324,6 +3359,20 @@ llvm::Constant *CodeGenFunction::EmitCheckTypeDescriptor(QualType T) {
       DiagnosticsEngine::ak_qualtype, (intptr_t)T.getAsOpaquePtr(), StringRef(),
       StringRef(), std::nullopt, Buffer, std::nullopt);
 
+  if (IsBitInt) {
+    // The Structure is: 0 to end the string, 32 bit unsigned integer in target
+    // endianness, zero.
+    char S[6] = {'\0', '\0', '\0', '\0', '\0', '\0'};
----------------
earnol wrote:

This was initial idea proposed in https://github.com/llvm/llvm-project/issues/64100.
Parsing from the string is a reasonable idea, but 
1. It will put additional performance burden on the runtime as we will need to do parsing in the runtime. It will require either regexp or FSM for parsing. Please read comments above when i have been requested to change CHECK to DCHECK for the performance reasons. And using sscanf or regexp will definitely put much serious burden on runtime compared to icmp.
2. This string is not used for anything but for diagnostics currently. Probably putting additional meaning for it is fine, but ... (see next point)
3. It will go against already implemented principles where we using pre-parsed data. If we are allowed to parse the type we do not need Type and Kind members of the TypeDescriptor. All this information can be extracted from the type string as it will become the single source of truth.

https://github.com/llvm/llvm-project/pull/96240


More information about the cfe-commits mailing list