This is an archive of the discontinued LLVM Phabricator instance.

[clang] Add support for __builtin_memset_inline
ClosedPublic

Authored by gchatelet on Jun 2 2022, 11:22 AM.

Details

Summary

In the same spirit as D73543 and in reply to https://reviews.llvm.org/D126768#3549920 this patch is adding support for __builtin_memset_inline.

The idea is to get support from the compiler to easily write efficient memory function implementations.

This patch could be split in two:

  • one for the LLVM part adding the llvm.memset.inline.* intrinsics.
  • and another one for the Clang part providing the instrinsic as a builtin.

Diff Detail

Event Timeline

gchatelet created this revision.Jun 2 2022, 11:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 2 2022, 11:22 AM
gchatelet requested review of this revision.Jun 2 2022, 11:22 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 2 2022, 11:22 AM
gchatelet updated this revision to Diff 433858.Jun 2 2022, 1:22 PM
  • remove unused variable and rebase
rsmith added a subscriber: rsmith.Jun 2 2022, 1:58 PM
rsmith added inline comments.
clang/lib/CodeGen/CGBuilder.h
53

There are a lot of unrelated whitespace changes (clang-format, I assume) in this file. Can you produce a separate patch with just the whitespace changes and go ahead and check that in first?

clang/lib/Sema/SemaChecking.cpp
2293–2315

This custom checking seems unnecessary and also insufficient: you're not enforcing that the arguments have the right types. We should convert the arguments to this builtin in the same way we'd convert arguments for a normally-declared function, which you can achieve by removing the "t" flag from the builtin definition and removing all of this logic (except for the nonnull checking, which I don't think we have a way to model in Builtins.def yet).

Please do the same to __builtin_memcpy_inline, which is wrong in the same way. (For example, __builtin_memcpy_inline(1, 2, 3) crashes in code generation because it fails to perform proper conversions and type-checking on its arguments.)

gchatelet updated this revision to Diff 433978.Jun 3 2022, 12:55 AM
  • Rebase over formatted CGBuilder.h
gchatelet updated this revision to Diff 433982.Jun 3 2022, 1:27 AM
  • Fix sema checking
gchatelet marked 2 inline comments as done.Jun 3 2022, 1:27 AM
gchatelet added inline comments.
clang/lib/Sema/SemaChecking.cpp
2293–2315

Thx!

courbet added inline comments.Jun 3 2022, 2:04 AM
clang/test/Sema/builtins-memcpy-inline.cpp
11 ↗(On Diff #433982)

can you split this off (and the corresponding code) to a separate patch ?

llvm/docs/LangRef.rst
13898

take*

13898–13899

"an extra isvolatile argument"

13899

pointer*

llvm/include/llvm/IR/IntrinsicInst.h
993

update comment

llvm/include/llvm/IR/Intrinsics.td
654

"version" ? or "semantics"

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
7334

There is nothing preveting a target from emitting a call to memset here when AlwaysInline is true. Actually, X86SelectionDAGInfo does just that (this very patch is adding /* AlwaysInline */ false, to the getMemset call that handles the trailing bytes). It happens that because trailing bytes are typically small and therefore inline. it happens to work, but this should be verified somehow (or, maybe easier, AlwaysInline should be passed to EmitTargetCodeForMemset so it can do the right thing).

7344

Not that this is not strictly required to return a valid SDValue: Even with an "infinite" Limit in TLI.findOptimalMemOpLowering, a target that overrides this function could decide to just return false. I'm not sure what we want to do in this case.
So I think we should document findOptimalMemOpLowering to mention that the default implementation always returns a valid memop lowering if Limit is UINT_MAX and that target that decide to not provide a memop lowering *must* emit a valid one in EmitTargetCodeForMemset. Another option would be to call the generic TargetLowering::findOptimalMemOpLowering when the target declines to generate eithe ra memop lowering or target-specific code.

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
5928

memset

llvm/test/CodeGen/X86/memset-inline.ll
2

Add tests for other targets ?

22

I could see memset deciding to inline 129 bytes in the future. What about using a more absurdly large number ?

gchatelet updated this revision to Diff 434750.Jun 7 2022, 2:52 AM
gchatelet marked 2 inline comments as done.
  • rebase
clang/test/Sema/builtins-memcpy-inline.cpp
11 ↗(On Diff #433982)
gchatelet updated this revision to Diff 434793.Jun 7 2022, 5:59 AM
gchatelet marked 8 inline comments as done.
  • Address comments, add more codegen tests, rebase

Pending D127279 before making sure that all EmitTargetCodeForMemset implementations are enforcing AlwaysInline.

gchatelet updated this revision to Diff 435877.Jun 10 2022, 5:13 AM
gchatelet marked an inline comment as done.
  • Address comments
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
7334

I think this is OK now, I had to tweak the ARM selection dag as well.

7344

This one is more tricky. I've added a comment on the function and bypassed problematic cases but this is far from ideal.
The greedy nature of the algorithm makes it hard to understand the appropriate behavior.

I think this is worth stepping back and redesigning the abstraction in a subsequent patch.

courbet added inline comments.Jun 10 2022, 5:34 AM
llvm/include/llvm/CodeGen/SelectionDAGTargetInfo.h
79 ↗(On Diff #435877)

Add comment about honoring AlwaysInline ?

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
6983

"Makes sure no function call is generated", because technically the code can generate an accelerator call (e.g. rep stos)

7344

Let's assert that the returned value is non-default before returning.

gchatelet updated this revision to Diff 435883.Jun 10 2022, 5:49 AM
  • Address comments
gchatelet marked 4 inline comments as done.Jun 10 2022, 5:50 AM
courbet accepted this revision.Jun 10 2022, 6:01 AM
courbet added inline comments.
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
7347

maybe add when AlwaysInline to make the issue more obvious.

This revision is now accepted and ready to land.Jun 10 2022, 6:01 AM
gchatelet updated this revision to Diff 435890.Jun 10 2022, 6:12 AM
  • Update assert message
This revision was landed with ongoing or failed builds.Jun 10 2022, 6:22 AM
This revision was automatically updated to reflect the committed changes.
aganea added a subscriber: aganea.Oct 25 2022, 4:52 PM

Hello @gchatelet! This patches introduces a regression in a two-stage build using rpmalloc on Windows. Bisection lead me here. Would you have a chance to take a look please? Thanks in advance.

To reproduce, I used the following script (rename to make_llvm.bat)

C:\git\llvm-project>make_llvm.bat stage1
...
C:\git\llvm-project>ninja clang lld -C stage1
...
C:\git\llvm-project>make_llvm.bat stage2_rpmalloc
...
C:\git\llvm-project>ninja lld -C stage2_rpmalloc

generates:

[158/2714] Building C object lib\Support\CMakeFiles\LLVMSupport.dir\C_\git\rpmalloc\rpmalloc\rpmalloc.c.obj
FAILED: lib/Support/CMakeFiles/LLVMSupport.dir/C_/git/rpmalloc/rpmalloc/rpmalloc.c.obj
C:\git\llvm-project\stage1\bin\clang-cl.exe  /nologo -DENABLE_OVERRIDE -DENABLE_PRELOAD -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -IC:\git\llvm-project\stage2_rpmalloc\lib\Support -IC:\git\llvm-project\llvm\lib\Support -IC:\git\llvm-project\stage2_rpmalloc\include -IC:\git\llvm-project\llvm\include /GS- /D_ITERATOR_DEBUG_LEVEL=0 -Xclang -O3 -fstrict-aliasing -march=native -flto=thin -fwhole-program-vtables -fuse-ld=lld /Zc:inline /Zi -gcodeview-ghash /Zc:strictStrings /Oi /W4  -Wextra -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wstring-conversion -Wmisleading-indentation /Gw -flto=thin /MT /O2 /Ob2 /DNDEBUG /showIncludes /Folib\Support\CMakeFiles\LLVMSupport.dir\C_\git\rpmalloc\rpmalloc\rpmalloc.c.obj /Fdlib\Support\CMakeFiles\LLVMSupport.dir\LLVMSupport.pdb -c -- C:\git\rpmalloc\rpmalloc\rpmalloc.c
Assertion failed: isa<To>(Val) && "cast<Ty>() argument of incompatible type!", file C:/git/llvm-project/llvm/include\llvm/Support/Casting.h, line 578
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: C:\\git\\llvm-project\\stage1\\bin\\clang-cl.exe /nologo -DENABLE_OVERRIDE -DENABLE_PRELOAD -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -IC:\\git\\llvm-project\\stage2_rpmalloc\\lib\\Support -IC:\\git\\llvm-project\\llvm\\lib\\Support -IC:\\git\\llvm-project\\stage2_rpmalloc\\include -IC:\\git\\llvm-project\\llvm\\include /GS- /D_ITERATOR_DEBUG_LEVEL=0 -Xclang -O3 -fstrict-aliasing -march=native -flto=thin -fwhole-program-vtables -fuse-ld=lld /Zc:inline /Zi -gcodeview-ghash /Zc:strictStrings /Oi /W4 -Wextra -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wstring-conversion -Wmisleading-indentation /Gw -flto=thin /MT /O2 /Ob2 /DNDEBUG /showIncludes /Folib\\Support\\CMakeFiles\\LLVMSupport.dir\\C_\\git\\rpmalloc\\rpmalloc\\rpmalloc.c.obj /Fdlib\\Support\\CMakeFiles\\LLVMSupport.dir\\LLVMSupport.pdb -c -- C:\\git\\rpmalloc\\rpmalloc\\rpmalloc.c
1.      <eof> parser at end of file
2.      Optimizer
 #0 0x00007ff7f877ca86 HandleAbort C:\git\llvm-project\llvm\lib\Support\Windows\Signals.inc:418:0
 #1 0x00007ff7fcdfc6bb raise C:\git\llvm-project\stage1\minkernel\crts\ucrt\src\appcrt\misc\signal.cpp:547:0
 #2 0x00007ff7fcdf1ff4 abort C:\git\llvm-project\stage1\minkernel\crts\ucrt\src\appcrt\startup\abort.cpp:71:0
 #3 0x00007ff7fcdf2672 common_assert_to_stderr<wchar_t> C:\git\llvm-project\stage1\minkernel\crts\ucrt\src\appcrt\startup\assert.cpp:186:0
 #4 0x00007ff7fcdf251a _wassert C:\git\llvm-project\stage1\minkernel\crts\ucrt\src\appcrt\startup\assert.cpp:443:0
 #5 0x00007ff7f9b48e7b llvm::VNCoercion::analyzeLoadFromClobberingMemInst(class llvm::Type *, class llvm::Value *, class llvm::MemIntrinsic *, class llvm::DataLayout const &) C:\git\llvm-project\llvm\lib\Transforms\Utils\VNCoercion.cpp:381:0
 #6 0x00007ff7f85a1ec4 llvm::GVNPass::AnalyzeLoadAvailability(class llvm::LoadInst *, class llvm::MemDepResult, class llvm::Value *, struct llvm::gvn::AvailableValue &) C:\git\llvm-project\llvm\lib\Transforms\Scalar\GVN.cpp:1211:0
 #7 0x00007ff7f85a8a5c llvm::GVNPass::processLoad(class llvm::LoadInst *) C:\git\llvm-project\llvm\lib\Transforms\Scalar\GVN.cpp:2068:0
 #8 0x00007ff7f85aa465 llvm::GVNPass::processInstruction(class llvm::Instruction *) C:\git\llvm-project\llvm\lib\Transforms\Scalar\GVN.cpp:2483:0
 #9 0x00007ff7f85ab3ed llvm::GVNPass::processBlock(class llvm::BasicBlock *) C:\git\llvm-project\llvm\lib\Transforms\Scalar\GVN.cpp:2682:0
#10 0x00007ff7f85aadd0 llvm::GVNPass::iterateOnFunction(class llvm::Function &) C:\git\llvm-project\llvm\lib\Transforms\Scalar\GVN.cpp:3027:0
#11 0x00007ff7f85a099d llvm::GVNPass::runImpl(class llvm::Function &, class llvm::AssumptionCache &, class llvm::DominatorTree &, class llvm::TargetLibraryInfo const &, class llvm::AAResults &, class llvm::MemoryDependenceResults *, class llvm::LoopInfo *, class llvm::OptimizationRemarkEmitter *, class llvm::MemorySSA *) C:\git\llvm-project\llvm\lib\Transforms\Scalar\GVN.cpp:2627:0
#12 0x00007ff7f85a0595 llvm::GVNPass::run(class llvm::Function &, class llvm::AnalysisManager<class llvm::Function> &) C:\git\llvm-project\llvm\lib\Transforms\Scalar\GVN.cpp:732:0
#13 0x00007ff7fb2f5771 llvm::detail::PassModel<class llvm::Function, class llvm::GVNPass, class llvm::PreservedAnalyses, class llvm::AnalysisManager<class llvm::Function>>::run(class llvm::Function &, class llvm::AnalysisManager<class llvm::Function> &) C:\git\llvm-project\llvm\include\llvm\IR\PassManagerInternal.h:88:0
#14 0x00007ff7f8eba44f llvm::PassManager<class llvm::Function, class llvm::AnalysisManager<class llvm::Function>>::run(class llvm::Function &, class llvm::AnalysisManager<class llvm::Function> &) C:\git\llvm-project\llvm\include\llvm\IR\PassManager.h:522:0
#15 0x00007ff7f7faed21 llvm::detail::PassModel<class llvm::Function, class llvm::PassManager<class llvm::Function, class llvm::AnalysisManager<class llvm::Function>>, class llvm::PreservedAnalyses, class llvm::AnalysisManager<class llvm::Function>>::run(class llvm::Function &, class llvm::AnalysisManager<class llvm::Function> &) C:\git\llvm-project\llvm\include\llvm\IR\PassManagerInternal.h:88:0
#16 0x00007ff7f8ec1d7e llvm::CGSCCToFunctionPassAdaptor::run(class llvm::LazyCallGraph::SCC &, class llvm::AnalysisManager<class llvm::LazyCallGraph::SCC, class llvm::LazyCallGraph &> &, class llvm::LazyCallGraph &, struct llvm::CGSCCUpdateResult &) C:\git\llvm-project\llvm\lib\Analysis\CGSCCPassManager.cpp:554:0
#17 0x00007ff7f7fb094d llvm::detail::PassModel<class llvm::LazyCallGraph::SCC, class llvm::CGSCCToFunctionPassAdaptor, class llvm::PreservedAnalyses, class llvm::AnalysisManager<class llvm::LazyCallGraph::SCC, class llvm::LazyCallGraph &>, class llvm::LazyCallGraph &, struct llvm::CGSCCUpdateResult &>::run(class llvm::LazyCallGraph::SCC &, class llvm::AnalysisManager<class llvm::LazyCallGraph::SCC, class llvm::LazyCallGraph &> &, class llvm::LazyCallGraph &, struct llvm::CGSCCUpdateResult &) C:\git\llvm-project\llvm\include\llvm\IR\PassManagerInternal.h:88:0
#18 0x00007ff7f8ebc8c1 llvm::PassManager<class llvm::LazyCallGraph::SCC, class llvm::AnalysisManager<class llvm::LazyCallGraph::SCC, class llvm::LazyCallGraph &>, class llvm::LazyCallGraph &, struct llvm::CGSCCUpdateResult &>::run(class llvm::LazyCallGraph::SCC &, class llvm::AnalysisManager<class llvm::LazyCallGraph::SCC, class llvm::LazyCallGraph &> &, class llvm::LazyCallGraph &, struct llvm::CGSCCUpdateResult &) C:\git\llvm-project\llvm\lib\Analysis\CGSCCPassManager.cpp:90:0
#19 0x00007ff7f989597d llvm::detail::PassModel<class llvm::LazyCallGraph::SCC, class llvm::PassManager<class llvm::LazyCallGraph::SCC, class llvm::AnalysisManager<class llvm::LazyCallGraph::SCC, class llvm::LazyCallGraph &>, class llvm::LazyCallGraph &, struct llvm::CGSCCUpdateResult &>, class llvm::PreservedAnalyses, class llvm::AnalysisManager<class llvm::LazyCallGraph::SCC, class llvm::LazyCallGraph &>, class llvm::LazyCallGraph &, struct llvm::CGSCCUpdateResult &>::run(class llvm::LazyCallGraph::SCC &, class llvm::AnalysisManager<class llvm::LazyCallGraph::SCC, class llvm::LazyCallGraph &> &, class llvm::LazyCallGraph &, struct llvm::CGSCCUpdateResult &) C:\git\llvm-project\llvm\include\llvm\IR\PassManagerInternal.h:88:0
#20 0x00007ff7f8ebffe1 llvm::DevirtSCCRepeatedPass::run(class llvm::LazyCallGraph::SCC &, class llvm::AnalysisManager<class llvm::LazyCallGraph::SCC, class llvm::LazyCallGraph &> &, class llvm::LazyCallGraph &, struct llvm::CGSCCUpdateResult &) C:\git\llvm-project\llvm\lib\Analysis\CGSCCPassManager.cpp:417:0
#21 0x00007ff7f9895e4d llvm::detail::PassModel<class llvm::LazyCallGraph::SCC, class llvm::DevirtSCCRepeatedPass, class llvm::PreservedAnalyses, class llvm::AnalysisManager<class llvm::LazyCallGraph::SCC, class llvm::LazyCallGraph &>, class llvm::LazyCallGraph &, struct llvm::CGSCCUpdateResult &>::run(class llvm::LazyCallGraph::SCC &, class llvm::AnalysisManager<class llvm::LazyCallGraph::SCC, class llvm::LazyCallGraph &> &, class llvm::LazyCallGraph &, struct llvm::CGSCCUpdateResult &) C:\git\llvm-project\llvm\include\llvm\IR\PassManagerInternal.h:88:0
#22 0x00007ff7f8ebeeb0 llvm::ModuleToPostOrderCGSCCPassAdaptor::run(class llvm::Module &, class llvm::AnalysisManager<class llvm::Module> &) C:\git\llvm-project\llvm\lib\Analysis\CGSCCPassManager.cpp:283:0
#23 0x00007ff7f9895b91 llvm::detail::PassModel<class llvm::Module, class llvm::ModuleToPostOrderCGSCCPassAdaptor, class llvm::PreservedAnalyses, class llvm::AnalysisManager<class llvm::Module>>::run(class llvm::Module &, class llvm::AnalysisManager<class llvm::Module> &) C:\git\llvm-project\llvm\include\llvm\IR\PassManagerInternal.h:88:0
#24 0x00007ff7f8eb9744 llvm::PassManager<class llvm::Module, class llvm::AnalysisManager<class llvm::Module>>::run(class llvm::Module &, class llvm::AnalysisManager<class llvm::Module> &) C:\git\llvm-project\llvm\include\llvm\IR\PassManager.h:522:0
#25 0x00007ff7f989504c llvm::ModuleInlinerWrapperPass::run(class llvm::Module &, class llvm::AnalysisManager<class llvm::Module> &) C:\git\llvm-project\llvm\lib\Transforms\IPO\Inliner.cpp:1150:0
#26 0x00007ff7fb2f6621 llvm::detail::PassModel<class llvm::Module, class llvm::ModuleInlinerWrapperPass, class llvm::PreservedAnalyses, class llvm::AnalysisManager<class llvm::Module>>::run(class llvm::Module &, class llvm::AnalysisManager<class llvm::Module> &) C:\git\llvm-project\llvm\include\llvm\IR\PassManagerInternal.h:88:0
#27 0x00007ff7f8eb9744 llvm::PassManager<class llvm::Module, class llvm::AnalysisManager<class llvm::Module>>::run(class llvm::Module &, class llvm::AnalysisManager<class llvm::Module> &) C:\git\llvm-project\llvm\include\llvm\IR\PassManager.h:522:0
#28 0x00007ff7f9cd6282 `anonymous namespace'::EmitAssemblyHelper::RunOptimizationPipeline C:\git\llvm-project\clang\lib\CodeGen\BackendUtil.cpp:965:0
#29 0x00007ff7f9cce34e clang::EmitBackendOutput(class clang::DiagnosticsEngine &, class clang::HeaderSearchOptions const &, class clang::CodeGenOptions const &, class clang::TargetOptions const &, class clang::LangOptions const &, class llvm::StringRef, class llvm::Module *, enum clang::BackendAction, class std::unique_ptr<class llvm::raw_pwrite_stream, struct std::default_delete<class llvm::raw_pwrite_stream>>) C:\git\llvm-project\clang\lib\CodeGen\BackendUtil.cpp:1181:0
#30 0x00007ff7fa0b26ae clang::BackendConsumer::HandleTranslationUnit(class clang::ASTContext &) C:\git\llvm-project\clang\lib\CodeGen\CodeGenAction.cpp:379:0
#31 0x00007ff7fbaf08e4 clang::ParseAST(class clang::Sema &, bool, bool) C:\git\llvm-project\clang\lib\Parse\ParseAST.cpp:182:0
#32 0x00007ff7fa017775 clang::FrontendAction::Execute(void) C:\git\llvm-project\clang\lib\Frontend\FrontendAction.cpp:1032:0
#33 0x00007ff7f88eca63 clang::CompilerInstance::ExecuteAction(class clang::FrontendAction &) C:\git\llvm-project\clang\lib\Frontend\CompilerInstance.cpp:1033:0
#34 0x00007ff7f8989667 clang::ExecuteCompilerInvocation(class clang::CompilerInstance *) C:\git\llvm-project\clang\lib\FrontendTool\ExecuteCompilerInvocation.cpp:266:0
#35 0x00007ff7f7f184c9 cc1_main(class llvm::ArrayRef<char const *>, char const *, void *) C:\git\llvm-project\clang\tools\driver\cc1_main.cpp:248:0
#36 0x00007ff7f7f14fc3 ExecuteCC1Tool C:\git\llvm-project\clang\tools\driver\driver.cpp:317:0
#37 0x00007ff7f9dd7236 llvm::function_ref<void ()>::callback_fn<`lambda at C:/git/llvm-project/clang/lib/Driver/Job.cpp:407:22'> C:\git\llvm-project\llvm\include\llvm\ADT\STLFunctionalExtras.h:45:0
#38 0x00007ff7f873317e llvm::CrashRecoveryContext::RunSafely(class llvm::function_ref<(void)>) C:\git\llvm-project\llvm\lib\Support\CrashRecoveryContext.cpp:234:0
#39 0x00007ff7f9dd6eed clang::driver::CC1Command::Execute(class llvm::ArrayRef<class llvm::Optional<class llvm::StringRef>>, class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>> *, bool *) const C:\git\llvm-project\clang\lib\Driver\Job.cpp:407:0
#40 0x00007ff7f88a9d3a clang::driver::Compilation::ExecuteCommand(class clang::driver::Command const &, class clang::driver::Command const *&) const C:\git\llvm-project\clang\lib\Driver\Compilation.cpp:196:0
#41 0x00007ff7f88aa20a clang::driver::Compilation::ExecuteJobs(class clang::driver::JobList const &, class llvm::SmallVectorImpl<struct std::pair<int, class clang::driver::Command const *>> &) const C:\git\llvm-project\clang\lib\Driver\Compilation.cpp:249:0
#42 0x00007ff7f88c3107 clang::driver::Driver::ExecuteCompilation(class clang::driver::Compilation &, class llvm::SmallVectorImpl<struct std::pair<int, class clang::driver::Command const *>> &) C:\git\llvm-project\clang\lib\Driver\Driver.cpp:1709:0
#43 0x00007ff7f7f148b1 clang_main(int, char **) C:\git\llvm-project\clang\tools\driver\driver.cpp:513:0
#44 0x00007ff7fcdde008 __scrt_common_main_seh D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288:0
#45 0x00007ff8f4944ed0 (C:\Windows\System32\KERNEL32.DLL+0x14ed0)
#46 0x00007ff8f529e40b (C:\Windows\SYSTEM32\ntdll.dll+0x7e40b)
clang-cl: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 15.0.0 (https://github.com/llvm/llvm-project.git 38637ee477541370a90b37f149069d8e5c0c2efd)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\git\llvm-project\stage1\bin
clang-cl: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-cl: note: diagnostic msg: C:\Users\aganea\AppData\Local\Temp\2\rpmalloc-70541f.c
clang-cl: note: diagnostic msg: C:\Users\aganea\AppData\Local\Temp\2\rpmalloc-70541f.sh
clang-cl: note: diagnostic msg:

********************

The reproducer:

Using rpmalloc at this revision: https://github.com/mjansson/rpmalloc/commit/f56e2f6794eab5c280b089c90750c681679fde92

aganea added a subscriber: thieta.Oct 25 2022, 4:56 PM

It's not really a regression, just a bug in the feature. The rpmalloc code is checking __has_builtin(__builtin_memset_inline), so older versions of clang aren't seeing the same source code.

We have been building a two stage clang and our internal projects with this version of rpmalloc and clang 15.x a while now and I haven't see the issue you see @aganea. I don't think this patch is the problem as @efriedma suggested, could be in rpmalloc but since I have used this successfully already I am not sure about that either.

I think there's a bug in the code though:

// If this is memset, we just need to see if the offset is valid in the size
  // of the memset..
  if (MI->getIntrinsicID() == Intrinsic::memset)

should really be:

// If this is memset, we just need to see if the offset is valid in the size
  // of the memset..
  if (isa<MemSetInst>(MI))

I think there's a bug in the code though:

// If this is memset, we just need to see if the offset is valid in the size
  // of the memset..
  if (MI->getIntrinsicID() == Intrinsic::memset)

should really be:

// If this is memset, we just need to see if the offset is valid in the size
  // of the memset..
  if (isa<MemSetInst>(MI))

Yes this seems a likely culprit.

It should be fixed now @aganea . Can you check?

It should be fixed now @aganea . Can you check?

Works now, thanks again for the quick response. Should D136752 be cherry-picked into the 15.0 branch?

We have been building a two stage clang and our internal projects with this version of rpmalloc and clang 15.x a while now and I haven't see the issue you see @aganea. I don't think this patch is the problem as @efriedma suggested, could be in rpmalloc but since I have used this successfully already I am not sure about that either.

Is your internal build using the rpmalloc develop branch?

It should be fixed now @aganea . Can you check?

Works now, thanks again for the quick response. Should D136752 be cherry-picked into the 15.0 branch?

Yes done here : https://github.com/llvm/llvm-project/issues/58627