[PATCH] D133202: [Clang] Avoid __builtin_assume_aligned crash when the 1st arg is array type

Lin Yurong via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 8 06:15:50 PDT 2022


yronglin added a comment.

Thanks a lot for your comments @rsmith @rjmccall .

Firstly, as far as I know, turning on the `-fsanitizer=alignment` options when calling `__builtin_assume_aligned` in C code, Clang will emit `call void @__ubsan_handle_alignment_assumption(...)` in CodeGen,  and CodeGen need `user-written-type` to generate correct `TypeDescriptor` (this class in compiler-rt/UBSan).

Secondly, before this patch, `clang::CodeGen::CodeGenFunction::emitAlignmentAssumption` use `CastExpr->getSubExprAsWritten` to get `user-written-type` in CodeGen,  In `Diff 457643` , with John's comments, we use custom sema checking. we  just use `DefaultFunctionArrayLvalueConversion` to convert 1st arg, but not implicit cast 1st arg to `const void *`(We expect pass `user-written-type` to CodeGen).

Unfortunately,  `Diff 457643` broken windows sanitize test, because there have a forward declaration `__MACHINE(void * __cdecl __builtin_assume_aligned(const void *, size_t, ...) noexcept)`in `intrin0.inl.h`, I think the reason for this problem is we use `nct` in `BUILTIN(__builtin_assume_aligned, "v*vC*z.", "nct")`, I try to find a solution based on `Diff 457643`, what do you all think about?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133202/new/

https://reviews.llvm.org/D133202



More information about the cfe-commits mailing list