[PATCH] D131979: [clang][UBSan] Fix __builtin_assume_aligned crash

Wang Yihan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 23 05:35:59 PDT 2022


yihanaa added a comment.

As far as I know, turning on the -fsanitizer=alignment options when calling __builtin_assume_aligned in C code, if
the 1st arg has volatile qualifier, Clang will emit "call void @__ubsan_handle_alignment_assumption(...)" in CodeGen,
else Clang will emit an warning and ignore "call void @__ubsan_handle_alignment_assumption(...)". But the same situation in C++, 
Clang will generate an error in Sema.

So I think, in order to keep this patch consistent with recent version of Clang and GCC behavior, when compile C code, Clang
should not directly emit an error and exit in Sema, but should check the 1st arg's volatile qualifier in CodeGen and decide 
whether to emit "call void @__ubsan_handle_alignment_assumption(...)".

But, I agree to use other ways to replace use getSubExprAsWritten() in CodeGen to check the 1st arg 'isVolatile', what do you all think about?

For more information about UBSan, see https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html and search 'volatile' on this website.

"The null, alignment, object-size, local-bounds, and vptr checks do not apply to pointers to types with the volatile qualifier."
C https://godbolt.org/z/xv35fG14r
C++ https://godbolt.org/z/qfje6sErE


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131979



More information about the cfe-commits mailing list