From: Brian Gesiak Date: Sun, 1 Apr 2018 23:55:21 +0000 (+0000) Subject: [Coroutines] Schedule coro-split before asan X-Git-Tag: llvmorg-7.0.0-rc1~9239 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=91a4b5af3a1f12c2a664faaef59fcf8eb86b1087;p=platform%2Fupstream%2Fllvm.git [Coroutines] Schedule coro-split before asan Summary: The docs for the LLVM coroutines intrinsic `@llvm.coro.id` state that "The second argument, if not null, designates a particular alloca instruction to be a coroutine promise." However, if the address sanitizer pass is run before the `@llvm.coro.id` intrinsic is lowered, the `alloca` instruction passed to the intrinsic as its second argument is converted, as per the https://github.com/google/sanitizers/wiki/AddressSanitizerAlgorithm docs, to an `inttoptr` instruction that accesses the address of the promise. On optimization levels `-O1` and above, the `-asan` pass is run after `-coro-early`, `-coro-split`, and `-coro-elide`, and before `-coro-cleanup`, and so there is no issue. At `-O0`, however, `-asan` is run in between `-coro-early` and `-coro-split`, which causes an assertion to be hit when the `inttoptr` instruction is forcibly cast to an `alloca`. Rearrange the passes such that the coroutine passes are registered before the sanitizer passes. Test Plan: Compile a simple C++ program that uses coroutines in `-O0` with `-fsanitize-address`, and confirm no assertion is hit: `clang++ coro-example.cpp -fcoroutines-ts -g -fsanitize=address -fno-omit-frame-pointer`. Reviewers: GorNishanov, lewissbaker, EricWF Reviewed By: GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D43927 llvm-svn: 328951 --- diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 02b1b1b..2eb8b6c 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -541,6 +541,9 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM, addObjCARCOptPass); } + if (LangOpts.CoroutinesTS) + addCoroutinePassesToExtensionPoints(PMBuilder); + if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds)) { PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate, addBoundsCheckingPass); @@ -599,9 +602,6 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM, addDataFlowSanitizerPass); } - if (LangOpts.CoroutinesTS) - addCoroutinePassesToExtensionPoints(PMBuilder); - if (LangOpts.Sanitize.hasOneOf(SanitizerKind::Efficiency)) { PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast, addEfficiencySanitizerPass);