[PATCH] D129448: [CodeGen][Asan] Emit lifetime intrinsic for bypassed label

luxufan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 10 09:56:06 PDT 2022


StephenFan created this revision.
StephenFan added reviewers: MaskRay, vitalybuka, rsmith.
Herald added a project: All.
StephenFan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix https://github.com/llvm/llvm-project/issues/56356
For following test case:

  extern int bar(char *A, int n);
  void goto_bypass(void) {
    {
      char x;
    l1:
      bar(&x, 1);
    }
    goto l1;
  }

And using `clang -cc1 -O2 -S -emit-llvm` to compile it.

  In the past, due to the existence of bypassed label, the lifetime

intrinsic would not be generated. This was also the cause of pr56356.

  In this patch, if the variable is bypassed, we do variable

allocation, emit lifetime-start intrinsic and record the lifetime-start
intrinsic in LexicalScope. Then When emitting the bypass label, we emit
the lifetime instrinsic again to make sure the lifetime of the bypassed
variable is start again. Address sanitizer will capture these lifetime
intrinsics and instrument poison and unpoison code. Finally pr56356 can
be resolved.

Here is the new llvm-ir of the test case above.

  define dso_local void @goto_bypass() local_unnamed_addr #0 {
  entry:
    %x = alloca i8, align 1
    call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %x) #3
    br label %l1
  
  l1:                                               ; preds = %l1, %entry
    call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %x) #3
    %call = call i32 @bar(ptr noundef nonnull %x, i32 noundef 1) #3
    call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %x) #3
    br label %l1
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129448

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGen/lifetime2.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129448.443515.patch
Type: text/x-patch
Size: 6092 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220710/707a1b96/attachment-0001.bin>


More information about the cfe-commits mailing list