[clang] [Clang] Add fake use emission to Clang with -fextend-lifetimes (PR #110102)

Jeremy Morse via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 29 08:54:53 PST 2024


================
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 %s -O0 -disable-O0-optnone -emit-llvm -fextend-lifetimes -fsanitize=null -fsanitize-trap=null -o - | FileCheck --check-prefixes=CHECK,NULL --implicit-check-not=ubsantrap %s
+// RUN: %clang_cc1 %s -O0 -disable-O0-optnone -emit-llvm -fextend-lifetimes -o - | FileCheck %s
+
+// With -fextend-lifetimes, the compiler previously generated a fake.use of any
+// reference variable at the end of the scope in which its alloca exists. This
+// caused two issues, where we would get fake uses for uninitialized variables
+// if that variable was declared after an early-return, and UBSan's null checks
+// would complain about this.
+// This test verifies that UBSan does not produce null-checks for arguments to
+// llvm.fake.use, and that fake uses are not emitted for a variable on paths
+// it has not been declared.
----------------
jmorse wrote:

Thanks for regenerating this with no optimisations happening; am I right in thinking that `-fsanitize=null` doesn't just turn off the sanitizer, it turns on ubsan for null values or something? I see there are calls to ubsantrap being generated, and want to settle my understanding of this.

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


More information about the cfe-commits mailing list