Page MenuHomePhabricator

Resubmit "[Alignment][NFC] Deprecate CreateMemCpy/CreateMemMove"
ClosedPublic

Authored by gchatelet on Dec 16 2019, 6:51 AM.

Details

Summary

This is a resubmit of D71473.

This patch introduces a set of functions to enable deprecation of IRBuilder functions without breaking out of tree clients.
Functions will be deprecated one by one and as in tree code is cleaned up.

This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790

Diff Detail

Event Timeline

gchatelet created this revision.Dec 16 2019, 6:51 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 16 2019, 6:51 AM
gchatelet updated this revision to Diff 234055.Dec 16 2019, 6:55 AM
  • rebase to get the correct diff
aaron.ballman accepted this revision.Dec 16 2019, 9:34 AM

When I apply locally and build, I get no additional warnings so this LGTM. Thanks!

This revision is now accepted and ready to land.Dec 16 2019, 9:34 AM

When I apply locally and build, I get no additional warnings so this LGTM. Thanks!

Thx a lot for checking !

This revision was automatically updated to reflect the committed changes.
aganea added a subscriber: aganea.Jan 16 2020, 8:09 AM

Hi! Since this is the last commit in Instructions.cpp, you can maybe help?

I'm seeing an assertion in one of our projects. I'm at rG28bb43bdf808c7e737eabfb6f6a368ace9086a9f.
I'm using the following cmake to build on Windows:

> set LLVM=c:/Program Files/LLVM
> %LLVM%\bin\clang-cl --version
clang version 9.0.0 (tags/RELEASE_900/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin

> cmake -GNinja %ROOT%/llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_OPTIMIZED_TABLEGEN=true -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_USE_CRT_RELEASE=MT -DCMAKE_C_COMPILER="%LLVM%/bin/clang-cl.EXE" -DCMAKE_CXX_COMPILER="%LLVM%/bin/clang-cl.EXE" -DCMAKE_LINKER="%LLVM%/bin/link.EXE" -DLLVM_ENABLE_PDB=true -DCMAKE_CXX_FLAGS="/GS- /D_ITERATOR_DEBUG_LEVEL=0 /arch:AVX2" -DCMAKE_C_FLAGS="/GS- /D_ITERATOR_DEBUG_LEVEL=0 /arch:AVX2" -DLLVM_ENABLE_PROJECTS="llvm;clang;lld" -DLLVM_ENABLE_PDB=ON

The assertion is this:

Assertion failed: !(isAtomic() && getAlignment() == 0) && "Alignment required for atomic load", file D:\llvm-project\llvm\lib\IR\Instructions.cpp, line 1287
Stack dump:
0.	Program arguments: D:\llvm-project\buildNinjaRel\bin\clang-cl.exe (stripped).cpp /Fo(stripped).obj /c /Yu(stripped).h /Fp(stripped).pch /FI(stripped).h (stripped project-specific /I) /Z7 /nologo /W0 /WX- (stripped project-specific /D)  /DWIN32_LEAN_AND_MEAN /DWIN64 /DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP /D_ENABLE_EXTENDED_ALIGNED_STORAGE /D_LIB /D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS /D_WIN32_WINNT=0x0601 /D__clang__=1 /GF /EHsc /MT /GS /Gy- /fp:fast /fp:except- /Zc:wchar_t /Zc:forScope /Zc:inline /GR- /openmp- /Fd(stripped).pdb /Gd /wd4100 /wd4127 /wd4189 /wd4201 /wd4206 /wd4503 /wd4505 /wd4511 /wd4512 /wd4611 /wd4702 /wd4714 /wd4748 /wd4800 /TP -m64 -fmsc-version=1910 /errorReport:queue /D_MBCS /bigobj /FC /permissive- /Zc:twoPhase- /Zc:strictStrings /Zc:ternary- /Zo -fdiagnostics-absolute-paths -march=haswell -Wno-c++11-narrowing /O2 /Ob2 /Oi /Ot /Oy- /showIncludes
1.	<eof> parser at end of file
2.	Per-module optimization passes
3.	Running pass 'CallGraph Pass Manager' on module '(stripped).cpp'.
4.	Running pass 'Jump Threading' on function '(stripped)'
 #0 0x00007ff716254c56 HandleAbort D:\llvm-project\llvm\lib\Support\Windows\Signals.inc:408:0
 #1 0x00007ff719e994a5 raise minkernel\crts\ucrt\src\appcrt\misc\signal.cpp:547:0
 #2 0x00007ff719e8f13c abort minkernel\crts\ucrt\src\appcrt\startup\abort.cpp:71:0
 #3 0x00007ff719e8f7da common_assert_to_stderr<wchar_t> minkernel\crts\ucrt\src\appcrt\startup\assert.cpp:186:0
 #4 0x00007ff719e8f682 _wassert minkernel\crts\ucrt\src\appcrt\startup\assert.cpp:443:0
 #5 0x00007ff71657c161 llvm::LoadInst::LoadInst(class llvm::Type *, class llvm::Value *, class llvm::Twine const &, bool, struct llvm::MaybeAlign, enum llvm::AtomicOrdering, unsigned char, class llvm::Instruction *) D:\llvm-project\llvm\lib\IR\Instructions.cpp:1325:0
 #6 0x00007ff716587a5b llvm::LoadInst::cloneImpl(void) const D:\llvm-project\llvm\lib\IR\Instructions.cpp:4147:0
 #7 0x00007ff71680ca7c llvm::Instruction::clone(void) const D:\llvm-project\llvm\include\llvm\IR\Instruction.def:172:0
 #8 0x00007ff7160c85f1 llvm::JumpThreadingPass::CloneInstructions(class llvm::ilist_iterator<struct llvm::ilist_detail::node_options<class llvm::Instruction, 1, 0, void>, 0, 0>, class llvm::ilist_iterator<struct llvm::ilist_detail::node_options<class llvm::Instruction, 1, 0, void>, 0, 0>, class llvm::BasicBlock *, class llvm::BasicBlock *) D:\llvm-project\llvm\lib\Transforms\Scalar\JumpThreading.cpp:2001:0
 #9 0x00007ff7160c92b1 llvm::JumpThreadingPass::ThreadEdge(class llvm::BasicBlock *, class llvm::SmallVectorImpl<class llvm::BasicBlock *> const &, class llvm::BasicBlock *) D:\llvm-project\llvm\lib\Transforms\Scalar\JumpThreading.cpp:2105:0
#10 0x00007ff7160c6582 llvm::JumpThreadingPass::TryThreadEdge(class llvm::BasicBlock *, class llvm::SmallVectorImpl<class llvm::BasicBlock *> const &, class llvm::BasicBlock *) D:\llvm-project\llvm\lib\Transforms\Scalar\JumpThreading.cpp:2051:0
#11 0x00007ff7160c3209 llvm::JumpThreadingPass::ProcessThreadableEdges(class llvm::Value *, class llvm::BasicBlock *, enum llvm::jumpthreading::ConstantPreference, class llvm::Instruction *) D:\llvm-project\llvm\lib\Transforms\Scalar\JumpThreading.cpp:1720:0
#12 0x00007ff7160be44d llvm::JumpThreadingPass::ProcessBlock(class llvm::BasicBlock *) D:\llvm-project\llvm\lib\Transforms\Scalar\JumpThreading.cpp:0:0
#13 0x00007ff7160bc90b llvm::JumpThreadingPass::runImpl(class llvm::Function &, class llvm::TargetLibraryInfo *, class llvm::LazyValueInfo *, class llvm::AAResults *, class llvm::DomTreeUpdater *, bool, class std::unique_ptr<class llvm::BlockFrequencyInfo, struct std::default_delete<class llvm::BlockFrequencyInfo>>, class std::unique_ptr<class llvm::BranchProbabilityInfo, struct std::default_delete<class llvm::BranchProbabilityInfo>>) D:\llvm-project\llvm\lib\Transforms\Scalar\JumpThreading.cpp:397:0
#14 0x00007ff7160cbadd `anonymous namespace'::JumpThreading::runOnFunction D:\llvm-project\llvm\lib\Transforms\Scalar\JumpThreading.cpp:315:0
#15 0x00007ff715ebab56 llvm::FPPassManager::runOnFunction(class llvm::Function &) D:\llvm-project\llvm\lib\IR\LegacyPassManager.cpp:1481:0
#16 0x00007ff716f2e45b `anonymous namespace'::CGPassManager::runOnModule D:\llvm-project\llvm\lib\Analysis\CallGraphSCCPass.cpp:497:0
#17 0x00007ff715ebb4e1 llvm::legacy::PassManagerImpl::run(class llvm::Module &) D:\llvm-project\llvm\lib\IR\LegacyPassManager.cpp:1694:0
#18 0x00007ff717283634 clang::EmitBackendOutput(class clang::DiagnosticsEngine &, class clang::HeaderSearchOptions const &, class clang::CodeGenOptions const &, class clang::TargetOptions const &, class clang::LangOptions const &, class llvm::DataLayout const &, class llvm::Module *, enum clang::BackendAction, class std::unique_ptr<class llvm::raw_pwrite_stream, struct std::default_delete<class llvm::raw_pwrite_stream>>) D:\llvm-project\clang\lib\CodeGen\BackendUtil.cpp:1550:0
#19 0x00007ff7175cb82b clang::BackendConsumer::HandleTranslationUnit(class clang::ASTContext &) D:\llvm-project\clang\lib\CodeGen\CodeGenAction.cpp:339:0
#20 0x00007ff718cef6b3 clang::ParseAST(class clang::Sema &, bool, bool) D:\llvm-project\clang\lib\Parse\ParseAST.cpp:178:0
#21 0x00007ff71752fd95 clang::FrontendAction::Execute(void) D:\llvm-project\clang\lib\Frontend\FrontendAction.cpp:940:0
#22 0x00007ff71634a41b clang::CompilerInstance::ExecuteAction(class clang::FrontendAction &) D:\llvm-project\clang\lib\Frontend\CompilerInstance.cpp:965:0
#23 0x00007ff7163a8777 clang::ExecuteCompilerInvocation(class clang::CompilerInstance *) D:\llvm-project\clang\lib\FrontendTool\ExecuteCompilerInvocation.cpp:290:0
#24 0x00007ff715af788a cc1_main(class llvm::ArrayRef<char const *>, char const *, void *) D:\llvm-project\clang\tools\driver\cc1_main.cpp:239:0
#25 0x00007ff715af48aa ExecuteCC1Tool D:\llvm-project\clang\tools\driver\driver.cpp:340:0
#26 0x00007ff71736695e llvm::function_ref<void ()>::callback_fn<`lambda at D:\llvm-project\clang\lib\Driver\Job.cpp:402:22'> D:\llvm-project\llvm\include\llvm\ADT\STLExtras.h:108:0
#27 0x00007ff71620bf2a InvokeFunctionCall D:\llvm-project\llvm\lib\Support\CrashRecoveryContext.cpp:207:0
#28 0x00007ff71620beed llvm::CrashRecoveryContext::RunSafely(class llvm::function_ref<(void)>) D:\llvm-project\llvm\lib\Support\CrashRecoveryContext.cpp:214:0
#29 0x00007ff71736625a 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 D:\llvm-project\clang\lib\Driver\Job.cpp:402:0
#30 0x00007ff71631584f clang::driver::Compilation::ExecuteCommand(class clang::driver::Command const &, class clang::driver::Command const *&) const D:\llvm-project\clang\lib\Driver\Compilation.cpp:182:0
#31 0x00007ff716315bb9 clang::driver::Compilation::ExecuteJobs(class clang::driver::JobList const &, class llvm::SmallVectorImpl<struct std::pair<int, class clang::driver::Command const *>> &) const D:\llvm-project\clang\lib\Driver\Compilation.cpp:233:0
#32 0x00007ff716328c97 clang::driver::Driver::ExecuteCompilation(class clang::driver::Compilation &, class llvm::SmallVectorImpl<struct std::pair<int, class clang::driver::Command const *>> &) D:\llvm-project\clang\lib\Driver\Driver.cpp:1476:0
#33 0x00007ff715af3f59 main D:\llvm-project\clang\tools\driver\driver.cpp:493:0
#34 0x00007ff719e7b788 __scrt_common_main_seh d:\agent\_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288:0
#35 0x00007ffb60747bd4 (C:\WINDOWS\System32\KERNEL32.DLL+0x17bd4)
#36 0x00007ffb610eced1 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x6ced1)

I can try to c-reduce if that's necessary.

Can you help or should I ask on the mailing list?

aganea added a subscriber: hans.EditedFeb 24 2020, 11:22 AM

Reduced to:

// a.cpp
#include <vector>
struct SP {
  void WeakAddRef();
  void WeakRelease();
};
template <typename T> struct PtrBase {
  T *volatile P;
  ~PtrBase() {
    if (R)
      R->WeakRelease();
  }
  PtrBase(const PtrBase &O) : R(O.R) {
    if (R)
      R->WeakAddRef();
  }
  SP *R;
  bool IsValid() const { return P != nullptr; }
};
struct alignas(16) VectorSIMD4f {
  float V;
};
unsigned __int64 countAF() {
  class AF {
    VectorSIMD4f B;
  };
  struct PD {
    PtrBase<AF> P;
  };
  std::vector<PD> AFs;
  unsigned __int64 C = 0;
  for (auto A : AFs) {
    if (A.P.IsValid())
      ++C;
  }
  return C;
}

Build with:

clang-cl a.cpp /c /O1

Please see the message just above for the cmake command to build clang.

This occurs in trunk and the 10.0 branch as well. @gchatelet Would you have a chance to take a look?

hans added a comment.Feb 25 2020, 1:16 AM

Alexandre filed https://bugs.llvm.org/show_bug.cgi?id=45010 for this, and I've added a stand-alone repro.

This occurs in trunk and the 10.0 branch as well. @gchatelet Would you have a chance to take a look?

I could reproduce the failing assert with a clang built at rGbdbb894a52997c1679d7f716397435c95e637fb3 (Apr 20 2017) so this is not a regression but a latent bug that has been uncovered.
Please have a look at the bug for a more detailed answer.

I'm not sure how far the reduced example is from the real code but I suspect that using an auto& instead of auto for the foreach variable will fix the issue.

gchatelet added a subscriber: jfb.Feb 25 2020, 6:40 AM

@jfb do you mind having a look at the bug since it involves volatile? What's your take on it?

aganea added a comment.EditedFeb 25 2020, 6:41 AM

! In D71547#1891256, @gchatelet wrote:
I'm not sure how far the reduced example is from the real code but I suspect that using an auto& instead of auto for the foreach variable will fix the issue.

Using auto& does indeed fix the assert, I forgot to mention that :-)