[PATCH] D44672: [CodeGen] Disable UBSan for coroutine functions

Brian Gesiak via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 19 21:05:29 PDT 2018


modocache created this revision.
modocache added reviewers: GorNishanov, vsk, eric_niebler, lewissbaker.

As explained in http://lists.llvm.org/pipermail/llvm-dev/2018-March/121924.html,
the LLVM coroutines transforms are not yet able to move the
instructions for UBSan null checking past coroutine suspend boundaries.
For now, disable all UBSan checks when generating code for coroutines
functions.

I also considered an approach where only '-fsanitize=null' would be disabled,
However in practice this led to other LLVM errors when writing object files:
"Cannot represent a difference across sections". For now, disable all
UBSan checks until coroutine transforms are updated to handle them.

Test Plan:

1. check-clang
2. Compile the program in https://gist.github.com/modocache/54a036c3bf9c06882fe85122e105d153 using the '-fsanitize=null' option and confirm it does not crash during LLVM IR generation.


Repository:
  rC Clang

https://reviews.llvm.org/D44672

Files:
  lib/CodeGen/CodeGenFunction.cpp


Index: lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -1298,6 +1298,14 @@
 
   Stmt *Body = FD->getBody();
 
+  // TODO: As mentioned in the TODO added in https://reviews.llvm.org/rL280678,
+  // coro-split is not capable of moving spills whose users' users are not
+  // dominated by 'llvm.coro.begin'. '-fsanitize=null', for example, generates
+  // such code: null checks that occur before 'llvm.coro.begin'. For now,
+  // disable UBSan checks within coroutine function bodies.
+  if (Body && Body->getStmtClass() == Stmt::CoroutineBodyStmtClass)
+    SanOpts.clear();
+
   // Initialize helper which will detect jumps which can cause invalid lifetime
   // markers.
   if (Body && ShouldEmitLifetimeMarkers)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44672.139072.patch
Type: text/x-patch
Size: 841 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180320/0462f7eb/attachment-0001.bin>


More information about the cfe-commits mailing list