[clang-tools-extra] r347570 - [clang-tidy] Improving narrowing conversions

2018-11-26 Thread Guillaume Chatelet via cfe-commits
Author: gchatelet
Date: Mon Nov 26 08:25:55 2018
New Revision: 347570

URL: http://llvm.org/viewvc/llvm-project?rev=347570&view=rev
Log:
[clang-tidy] Improving narrowing conversions

Summary:
Newly flagged narrowing conversions:
 - integer to narrower signed integer (this is compiler implementation defined),
 - integer - floating point narrowing conversions,
 - floating point - integer narrowing conversions,
 - constants with narrowing conversions (even in ternary operator).

Reviewers: hokein, alexfh, aaron.ballman, JonasToth

Reviewed By: aaron.ballman, JonasToth

Subscribers: lebedev.ri, courbet, nemanjai, xazax.hun, kbarton, cfe-commits

Tags: #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D53488

Added:

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-long-is-32bits.cpp

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-narrowingfloatingpoint-option.cpp

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-pedanticmode-option.cpp

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-unsigned-char.cpp
Modified:

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.h
clang-tools-extra/trunk/docs/ReleaseNotes.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-narrowing-conversions.rst

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp?rev=347570&r1=347569&r2=347570&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
 Mon Nov 26 08:25:55 2018
@@ -9,7 +9,13 @@
 
 #include "NarrowingConversionsCheck.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Type.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/APSInt.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
+
+#include 
 
 using namespace clang::ast_matchers;
 
@@ -17,52 +23,423 @@ namespace clang {
 namespace tidy {
 namespace cppcoreguidelines {
 
-// FIXME: Check double -> float truncation. Pay attention to casts:
+NarrowingConversionsCheck::NarrowingConversionsCheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  WarnOnFloatingPointNarrowingConversion(
+  Options.get("WarnOnFloatingPointNarrowingConversion", 1)),
+  PedanticMode(Options.get("PedanticMode", 0)) {}
+
 void NarrowingConversionsCheck::registerMatchers(MatchFinder *Finder) {
   // ceil() and floor() are guaranteed to return integers, even though the type
   // is not integral.
-  const auto IsCeilFloorCall = callExpr(callee(functionDecl(
-  hasAnyName("::ceil", "::std::ceil", "::floor", "::std::floor";
-
-  const auto IsFloatExpr =
-  expr(hasType(realFloatingPointType()), unless(IsCeilFloorCall));
+  const auto IsCeilFloorCallExpr = expr(callExpr(callee(functionDecl(
+  hasAnyName("::ceil", "::std::ceil", "::floor", "::std::floor");
 
-  // casts:
+  // Casts:
   //   i = 0.5;
   //   void f(int); f(0.5);
-  Finder->addMatcher(implicitCastExpr(hasImplicitDestinationType(isInteger()),
-  hasSourceExpression(IsFloatExpr),
-  unless(hasParent(castExpr())),
-  unless(isInTemplateInstantiation()))
- .bind("cast"),
- this);
+  Finder->addMatcher(
+  implicitCastExpr(hasImplicitDestinationType(builtinType()),
+   hasSourceExpression(hasType(builtinType())),
+   unless(hasSourceExpression(IsCeilFloorCallExpr)),
+   unless(hasParent(castExpr())),
+   unless(isInTemplateInstantiation()))
+  .bind("cast"),
+  this);
 
   // Binary operators:
   //   i += 0.5;
-  Finder->addMatcher(
-  binaryOperator(isAssignmentOperator(),
- // The `=` case generates an implicit cast which is 
covered
- // by the previous matcher.
- unless(hasOperatorName("=")),
- hasLHS(hasType(isInteger())), hasRHS(IsFloatExpr),
- unless(isInTemplateInstantiation()))
-  .bind("op"),
-  this);
+  Finder->addMatcher(binaryOperator(isAssignmentOperator(),
+hasLHS(expr(hasType(builtinType(,
+   

r371742 - [Alignment] Move OffsetToAlignment to Alignment.h

2019-09-12 Thread Guillaume Chatelet via cfe-commits
Author: gchatelet
Date: Thu Sep 12 08:20:36 2019
New Revision: 371742

URL: http://llvm.org/viewvc/llvm-project?rev=371742&view=rev
Log:
[Alignment] Move OffsetToAlignment to Alignment.h

Summary:
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

Reviewers: courbet, JDevlieghere, alexshap, rupprecht, jhenderson

Subscribers: sdardis, nemanjai, hiraditya, kbarton, jakehehrlich, jrtc27, 
MaskRay, atanasyan, jsji, seiya, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D67499

Modified:
cfe/trunk/lib/AST/DeclBase.cpp

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=371742&r1=371741&r2=371742&view=diff
==
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Thu Sep 12 08:20:36 2019
@@ -100,7 +100,7 @@ void *Decl::operator new(std::size_t Siz
 // Ensure required alignment of the resulting object by adding extra
 // padding at the start if required.
 size_t ExtraAlign =
-llvm::OffsetToAlignment(sizeof(Module *), alignof(Decl));
+llvm::offsetToAlignment(sizeof(Module *), llvm::Align(alignof(Decl)));
 auto *Buffer = reinterpret_cast(
 ::operator new(ExtraAlign + sizeof(Module *) + Size + Extra, Ctx));
 Buffer += ExtraAlign;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r372562 - [Alignment] fix build

2019-09-23 Thread Guillaume Chatelet via cfe-commits
Author: gchatelet
Date: Mon Sep 23 02:04:12 2019
New Revision: 372562

URL: http://llvm.org/viewvc/llvm-project?rev=372562&view=rev
Log:
[Alignment] fix build

Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=372562&r1=372561&r2=372562&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Sep 23 02:04:12 2019
@@ -4132,11 +4132,12 @@ RValue CodeGenFunction::EmitCall(const C
 auto scalarAlign = 
CGM.getDataLayout().getPrefTypeAlignment(scalarType);
 
 // Materialize to a temporary.
-addr = CreateTempAlloca(RV.getScalarVal()->getType(),
-CharUnits::fromQuantity(std::max(
-layout->getAlignment(), scalarAlign)),
-"tmp",
-/*ArraySize=*/nullptr, &AllocaAddr);
+addr = CreateTempAlloca(
+RV.getScalarVal()->getType(),
+CharUnits::fromQuantity(std::max(
+(unsigned)layout->getAlignment().value(), scalarAlign)),
+"tmp",
+/*ArraySize=*/nullptr, &AllocaAddr);
 tempSize = EmitLifetimeStart(scalarSize, AllocaAddr.getPointer());
 
 Builder.CreateStore(RV.getScalarVal(), addr);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r373195 - [Alignment][NFC] Remove LoadInst::setAlignment(unsigned)

2019-09-30 Thread Guillaume Chatelet via cfe-commits
Author: gchatelet
Date: Mon Sep 30 02:37:05 2019
New Revision: 373195

URL: http://llvm.org/viewvc/llvm-project?rev=373195&view=rev
Log:
[Alignment][NFC] Remove LoadInst::setAlignment(unsigned)

Summary:
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

Reviewers: courbet, jdoerfert

Subscribers: hiraditya, asbirlea, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D68142

Modified:
cfe/trunk/lib/CodeGen/CGCleanup.cpp

Modified: cfe/trunk/lib/CodeGen/CGCleanup.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCleanup.cpp?rev=373195&r1=373194&r2=373195&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCleanup.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCleanup.cpp Mon Sep 30 02:37:05 2019
@@ -310,7 +310,7 @@ static void createStoreInstBefore(llvm::
 static llvm::LoadInst *createLoadInstBefore(Address addr, const Twine &name,
 llvm::Instruction *beforeInst) {
   auto load = new llvm::LoadInst(addr.getPointer(), name, beforeInst);
-  load->setAlignment(addr.getAlignment().getQuantity());
+  load->setAlignment(llvm::MaybeAlign(addr.getAlignment().getQuantity()));
   return load;
 }
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r373207 - [Alignment][NFC] Remove AllocaInst::setAlignment(unsigned)

2019-09-30 Thread Guillaume Chatelet via cfe-commits
Author: gchatelet
Date: Mon Sep 30 06:34:44 2019
New Revision: 373207

URL: http://llvm.org/viewvc/llvm-project?rev=373207&view=rev
Log:
[Alignment][NFC] Remove AllocaInst::setAlignment(unsigned)

Summary:
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

Reviewers: courbet

Subscribers: jholewinski, arsenm, jvesely, nhaehnle, eraman, hiraditya, 
cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D68141

Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/TargetInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=373207&r1=373206&r2=373207&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Mon Sep 30 06:34:44 2019
@@ -2366,7 +2366,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 .toCharUnitsFromBits(TI.getSuitableAlign())
 .getQuantity();
 AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
-AI->setAlignment(SuitableAlignmentInBytes);
+AI->setAlignment(MaybeAlign(SuitableAlignmentInBytes));
 initializeAlloca(*this, AI, Size, SuitableAlignmentInBytes);
 return RValue::get(AI);
   }
@@ -2379,7 +2379,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 unsigned AlignmentInBytes =
 CGM.getContext().toCharUnitsFromBits(AlignmentInBits).getQuantity();
 AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
-AI->setAlignment(AlignmentInBytes);
+AI->setAlignment(MaybeAlign(AlignmentInBytes));
 initializeAlloca(*this, AI, Size, AlignmentInBytes);
 return RValue::get(AI);
   }

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=373207&r1=373206&r2=373207&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Sep 30 06:34:44 2019
@@ -3841,7 +3841,7 @@ RValue CodeGenFunction::EmitCall(const C
   AI = CreateTempAlloca(ArgStruct, "argmem");
 }
 auto Align = CallInfo.getArgStructAlignment();
-AI->setAlignment(Align.getQuantity());
+AI->setAlignment(llvm::MaybeAlign(Align.getQuantity()));
 AI->setUsedWithInAlloca(true);
 assert(AI->isUsedWithInAlloca() && !AI->isStaticAlloca());
 ArgMemory = Address(AI, Align);

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=373207&r1=373206&r2=373207&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Sep 30 06:34:44 2019
@@ -66,7 +66,7 @@ Address CodeGenFunction::CreateTempAlloc
  const Twine &Name,
  llvm::Value *ArraySize) {
   auto Alloca = CreateTempAlloca(Ty, Name, ArraySize);
-  Alloca->setAlignment(Align.getQuantity());
+  Alloca->setAlignment(llvm::MaybeAlign(Align.getQuantity()));
   return Address(Alloca, Align);
 }
 

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=373207&r1=373206&r2=373207&view=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Mon Sep 30 06:34:44 2019
@@ -9954,7 +9954,7 @@ llvm::Function *AMDGPUTargetCodeGenInfo:
   Builder.SetInsertPoint(BB);
   unsigned BlockAlign = CGF.CGM.getDataLayout().getPrefTypeAlignment(BlockTy);
   auto *BlockPtr = Builder.CreateAlloca(BlockTy, nullptr);
-  BlockPtr->setAlignment(BlockAlign);
+  BlockPtr->setAlignment(llvm::MaybeAlign(BlockAlign));
   Builder.CreateAlignedStore(F->arg_begin(), BlockPtr, BlockAlign);
   auto *Cast = Builder.CreatePointerCast(BlockPtr, InvokeFT->getParamType(0));
   llvm::SmallVector Args;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r373592 - [Alignment][Clang][NFC] Add CharUnits::getAsAlign

2019-10-03 Thread Guillaume Chatelet via cfe-commits
Author: gchatelet
Date: Thu Oct  3 06:00:29 2019
New Revision: 373592

URL: http://llvm.org/viewvc/llvm-project?rev=373592&view=rev
Log:
[Alignment][Clang][NFC] Add CharUnits::getAsAlign

Summary:
This is a prerequisite to removing `llvm::GlobalObject::setAlignment(unsigned)`.
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

Reviewers: courbet

Subscribers: jholewinski, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D68274

Modified:
cfe/trunk/include/clang/AST/CharUnits.h
cfe/trunk/lib/CodeGen/CGCUDANV.cpp
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGCleanup.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/ConstantInitBuilder.cpp
cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp

Modified: cfe/trunk/include/clang/AST/CharUnits.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CharUnits.h?rev=373592&r1=373591&r2=373592&view=diff
==
--- cfe/trunk/include/clang/AST/CharUnits.h (original)
+++ cfe/trunk/include/clang/AST/CharUnits.h Thu Oct  3 06:00:29 2019
@@ -14,6 +14,7 @@
 #define LLVM_CLANG_AST_CHARUNITS_H
 
 #include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/Support/Alignment.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/MathExtras.h"
 
@@ -177,6 +178,10 @@ namespace clang {
   /// getQuantity - Get the raw integer representation of this quantity.
   QuantityType getQuantity() const { return Quantity; }
 
+  /// getAsAlign - Returns Quantity as a valid llvm::Align,
+  /// Beware llvm::Align assumes power of two 8-bit bytes.
+  llvm::Align getAsAlign() const { return llvm::Align(Quantity); }
+
   /// alignTo - Returns the next integer (mod 2**64) that is
   /// greater than or equal to this quantity and is a multiple of \p Align.
   /// Align must be non-zero.

Modified: cfe/trunk/lib/CodeGen/CGCUDANV.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCUDANV.cpp?rev=373592&r1=373591&r2=373592&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCUDANV.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCUDANV.cpp Thu Oct  3 06:00:29 2019
@@ -93,7 +93,7 @@ private:
   GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::None);
 }
 if (Alignment)
-  GV->setAlignment(Alignment);
+  GV->setAlignment(llvm::Align(Alignment));
 
 return llvm::ConstantExpr::getGetElementPtr(ConstStr.getElementType(),
 ConstStr.getPointer(), Zeros);
@@ -628,7 +628,7 @@ llvm::Function *CGNVCUDARuntime::makeMod
 Linkage,
 /*Initializer=*/llvm::ConstantPointerNull::get(VoidPtrPtrTy),
 "__hip_gpubin_handle");
-GpuBinaryHandle->setAlignment(CGM.getPointerAlign().getQuantity());
+GpuBinaryHandle->setAlignment(CGM.getPointerAlign().getAsAlign());
 // Prevent the weak symbol in different shared libraries being merged.
 if (Linkage != llvm::GlobalValue::InternalLinkage)
   GpuBinaryHandle->setVisibility(llvm::GlobalValue::HiddenVisibility);
@@ -669,7 +669,7 @@ llvm::Function *CGNVCUDARuntime::makeMod
 GpuBinaryHandle = new llvm::GlobalVariable(
 TheModule, VoidPtrPtrTy, false, llvm::GlobalValue::InternalLinkage,
 llvm::ConstantPointerNull::get(VoidPtrPtrTy), "__cuda_gpubin_handle");
-GpuBinaryHandle->setAlignment(CGM.getPointerAlign().getQuantity());
+GpuBinaryHandle->setAlignment(CGM.getPointerAlign().getAsAlign());
 CtorBuilder.CreateAlignedStore(RegisterFatbinCall, GpuBinaryHandle,
CGM.getPointerAlign());
 

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=373592&r1=373591&r2=373592&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Thu Oct  3 06:00:29 2019
@@ -3841,7 +3841,7 @@ RValue CodeGenFunction::EmitCall(const C
   AI = CreateTempAlloca(ArgStruct, "argmem");
 }
 auto Align = CallInfo.getArgStructAlignm

r373595 - [Alignment][NFC] Remove StoreInst::setAlignment(unsigned)

2019-10-03 Thread Guillaume Chatelet via cfe-commits
Author: gchatelet
Date: Thu Oct  3 06:17:21 2019
New Revision: 373595

URL: http://llvm.org/viewvc/llvm-project?rev=373595&view=rev
Log:
[Alignment][NFC] Remove StoreInst::setAlignment(unsigned)

Summary:
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

Reviewers: courbet, bollu, jdoerfert

Subscribers: hiraditya, asbirlea, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D68268

Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=373595&r1=373594&r2=373595&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Oct  3 06:17:21 2019
@@ -11193,7 +11193,7 @@ Value *CodeGenFunction::EmitX86BuiltinEx
 // Unaligned nontemporal store of the scalar value.
 StoreInst *SI = Builder.CreateDefaultAlignedStore(Src, BC);
 SI->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node);
-SI->setAlignment(1);
+SI->setAlignment(llvm::Align::None());
 return SI;
   }
   // Rotate is a special case of funnel shift - 1st 2 args are the same.


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r374884 - [Alignment] Migrate Attribute::getWith(Stack)Alignment

2019-10-15 Thread Guillaume Chatelet via cfe-commits
Author: gchatelet
Date: Tue Oct 15 05:56:24 2019
New Revision: 374884

URL: http://llvm.org/viewvc/llvm-project?rev=374884&view=rev
Log:
[Alignment] Migrate Attribute::getWith(Stack)Alignment

Summary:
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

Reviewers: courbet, jdoerfert

Reviewed By: courbet

Subscribers: arsenm, jvesely, nhaehnle, hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D68792

Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=374884&r1=374883&r2=374884&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Tue Oct 15 05:56:24 2019
@@ -2126,8 +2126,8 @@ void CodeGenModule::ConstructAttributeLi
   if (!PTy->isIncompleteType() && PTy->isConstantSizeType()) {
 auto info = getContext().getTypeInfoInChars(PTy);
 Attrs.addDereferenceableAttr(info.first.getQuantity());
-Attrs.addAttribute(llvm::Attribute::getWithAlignment(getLLVMContext(),
- info.second.getQuantity()));
+Attrs.addAttribute(llvm::Attribute::getWithAlignment(
+getLLVMContext(), info.second.getAsAlign()));
   }
   break;
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] bd87916 - [clang] Add no_builtin attribute

2019-10-28 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2019-10-28T17:30:11+01:00
New Revision: bd87916109483d33455cbf20da2309197b983cdd

URL: 
https://github.com/llvm/llvm-project/commit/bd87916109483d33455cbf20da2309197b983cdd
DIFF: 
https://github.com/llvm/llvm-project/commit/bd87916109483d33455cbf20da2309197b983cdd.diff

LOG: [clang] Add no_builtin attribute

Summary:
This is a follow up on https://reviews.llvm.org/D61634
This patch is simpler and only adds the no_builtin attribute.

Reviewers: tejohnson, courbet, theraven, t.p.northover, jdoerfert

Subscribers: mgrang, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D68028

Added: 
clang/test/CodeGen/no-builtin.cpp
clang/test/Sema/no-builtin.cpp

Modified: 
clang/include/clang/AST/Decl.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGCall.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index b3e7a570fd6d..16094c0988fa 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2031,6 +2031,10 @@ class FunctionDecl : public DeclaratorDecl,
   ///
   /// This does not determine whether the function has been defined (e.g., in a
   /// previous definition); for that information, use isDefined.
+  ///
+  /// Note: the function declaration does not become a definition until the
+  /// parser reaches the definition, if called before, this function will 
return
+  /// `false`.
   bool isThisDeclarationADefinition() const {
 return isDeletedAsWritten() || isDefaulted() || Body || hasSkippedBody() ||
isLateTemplateParsed() || willHaveBody() || hasDefiningAttr();

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 4557a614d361..d5018f444e1c 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3427,3 +3427,10 @@ def ObjCExternallyRetained : InheritableAttr {
   let Subjects = SubjectList<[NonParmVar, Function, Block, ObjCMethod]>;
   let Documentation = [ObjCExternallyRetainedDocs];
 }
+
+def NoBuiltin : Attr {
+  let Spellings = [Clang<"no_builtin">];
+  let Args = [VariadicStringArgument<"BuiltinNames">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [NoBuiltinDocs];
+}

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 6e79d0bb3631..9d0d27407573 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4413,3 +4413,40 @@ and is not a general mechanism for declaring arbitrary 
aliases for
 clang builtin functions.
   }];
 }
+
+def NoBuiltinDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+.. Note:: This attribute is not yet fully implemented, it is validated but has
+no effect on the generated code.
+
+The ``__attribute__((no_builtin))`` is similar to the ``-fno-builtin`` flag
+except it is specific to the body of a function. The attribute may also be
+applied to a virtual function but has no effect on the behavior of overriding
+functions in a derived class.
+
+It accepts one or more strings corresponding to the specific names of the
+builtins to disable (e.g. "memcpy", "memset").
+If the attribute is used without parameters it will disable all buitins at
+once.
+
+.. code-block:: c++
+
+  // The compiler is not allowed to add any builtin to foo's body.
+  void foo(char* data, size_t count) __attribute__((no_builtin)) {
+// The compiler is not allowed to convert the loop into
+// `__builtin_memset(data, 0xFE, count);`.
+for (size_t i = 0; i < count; ++i)
+  data[i] = 0xFE;
+  }
+
+  // The compiler is not allowed to add the `memcpy` builtin to bar's body.
+  void bar(char* data, size_t count) __attribute__((no_builtin("memcpy"))) {
+// The compiler is allowed to convert the loop into
+// `__builtin_memset(data, 0xFE, count);` but cannot generate any
+// `__builtin_memcpy`
+for (size_t i = 0; i < count; ++i)
+  data[i] = 0xFE;
+  }
+  }];
+}

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index db877a46c300..20670a98fe03 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3624,6 +3624,15 @@ def err_attribute_overloadable_no_prototype : Error<
 def err_attribute_overloadable_multiple_unmarked_overloads : Error<
   "at most one overload for a given name may lack the 'overloadable' "
   "attribute">;
+def warn_attribute_no_builtin_invalid_builtin_name : Warning<
+  "'%0' is not a valid builtin name for %1">,
+  InGroup>;
+def err_attribute_no_builtin_wil

Re: [clang] bd87916 - [clang] Add no_builtin attribute

2019-10-29 Thread Guillaume Chatelet via cfe-commits
hi Vlad,

I've spend a big part of my day digging into this and I'm less and less
convinced that my patch broke the builds.
IIUC the built bots are still failing although my patch has been
reverted for quite some time now.

Am I missing something?

On Mon, Oct 28, 2019 at 11:24 PM Vlad Tsyrklevich 
wrote:

> I've reverted this change as it was causing ASan/MSan failures in
> check-clang, e.g. take a look at the bottom 2 failures here:
> http://lab.llvm.org:8014/builders/sanitizer-x86_64-linux-bootstrap/builds/124/steps/check-clang%20asan/logs/stdio
>  or
> here
> http://lab.llvm.org:8014/builders/sanitizer-x86_64-linux-fast/builds/126/steps/check-clang%20msan/logs/stdio
>
> On Mon, Oct 28, 2019 at 9:30 AM Guillaume Chatelet via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>>
>> Author: Guillaume Chatelet
>> Date: 2019-10-28T17:30:11+01:00
>> New Revision: bd87916109483d33455cbf20da2309197b983cdd
>>
>> URL:
>> https://github.com/llvm/llvm-project/commit/bd87916109483d33455cbf20da2309197b983cdd
>> DIFF:
>> https://github.com/llvm/llvm-project/commit/bd87916109483d33455cbf20da2309197b983cdd.diff
>>
>> LOG: [clang] Add no_builtin attribute
>>
>> Summary:
>> This is a follow up on https://reviews.llvm.org/D61634
>> This patch is simpler and only adds the no_builtin attribute.
>>
>> Reviewers: tejohnson, courbet, theraven, t.p.northover, jdoerfert
>>
>> Subscribers: mgrang, cfe-commits
>>
>> Tags: #clang
>>
>> Differential Revision: https://reviews.llvm.org/D68028
>>
>> Added:
>> clang/test/CodeGen/no-builtin.cpp
>> clang/test/Sema/no-builtin.cpp
>>
>> Modified:
>> clang/include/clang/AST/Decl.h
>> clang/include/clang/Basic/Attr.td
>> clang/include/clang/Basic/AttrDocs.td
>> clang/include/clang/Basic/DiagnosticSemaKinds.td
>> clang/lib/CodeGen/CGCall.cpp
>> clang/lib/Sema/SemaDecl.cpp
>> clang/lib/Sema/SemaDeclAttr.cpp
>> clang/test/Misc/pragma-attribute-supported-attributes-list.test
>>
>> Removed:
>>
>>
>>
>>
>> 
>> diff  --git a/clang/include/clang/AST/Decl.h
>> b/clang/include/clang/AST/Decl.h
>> index b3e7a570fd6d..16094c0988fa 100644
>> --- a/clang/include/clang/AST/Decl.h
>> +++ b/clang/include/clang/AST/Decl.h
>> @@ -2031,6 +2031,10 @@ class FunctionDecl : public DeclaratorDecl,
>>///
>>/// This does not determine whether the function has been defined
>> (e.g., in a
>>/// previous definition); for that information, use isDefined.
>> +  ///
>> +  /// Note: the function declaration does not become a definition until
>> the
>> +  /// parser reaches the definition, if called before, this function
>> will return
>> +  /// `false`.
>>bool isThisDeclarationADefinition() const {
>>  return isDeletedAsWritten() || isDefaulted() || Body ||
>> hasSkippedBody() ||
>> isLateTemplateParsed() || willHaveBody() || hasDefiningAttr();
>>
>> diff  --git a/clang/include/clang/Basic/Attr.td
>> b/clang/include/clang/Basic/Attr.td
>> index 4557a614d361..d5018f444e1c 100644
>> --- a/clang/include/clang/Basic/Attr.td
>> +++ b/clang/include/clang/Basic/Attr.td
>> @@ -3427,3 +3427,10 @@ def ObjCExternallyRetained : InheritableAttr {
>>let Subjects = SubjectList<[NonParmVar, Function, Block, ObjCMethod]>;
>>let Documentation = [ObjCExternallyRetainedDocs];
>>  }
>> +
>> +def NoBuiltin : Attr {
>> +  let Spellings = [Clang<"no_builtin">];
>> +  let Args = [VariadicStringArgument<"BuiltinNames">];
>> +  let Subjects = SubjectList<[Function]>;
>> +  let Documentation = [NoBuiltinDocs];
>> +}
>>
>> diff  --git a/clang/include/clang/Basic/AttrDocs.td
>> b/clang/include/clang/Basic/AttrDocs.td
>> index 6e79d0bb3631..9d0d27407573 100644
>> --- a/clang/include/clang/Basic/AttrDocs.td
>> +++ b/clang/include/clang/Basic/AttrDocs.td
>> @@ -4413,3 +4413,40 @@ and is not a general mechanism for declaring
>> arbitrary aliases for
>>  clang builtin functions.
>>}];
>>  }
>> +
>> +def NoBuiltinDocs : Documentation {
>> +  let Category = DocCatFunction;
>> +  let Content = [{
>> +.. Note:: This attribute is not yet fully implemented, it is validated
>> but has
>> +no effect on the generated code.
>> +
>> +The ``__attribute__((no_builtin))`` is similar to the ``-fno-builtin``
>> flag

Re: [clang] bd87916 - [clang] Add no_builtin attribute

2019-10-29 Thread Guillaume Chatelet via cfe-commits
For instance here are the kind of errors I have by running a sanitized
clang on master (with or without my patch it doesn't make a difference)

cd /redacted/git/llvm-project/llvm/build-msan &&
> /redacted/git/llvm-project/llvm/build-msan/bin/llvm-tblgen
> -gen-opt-parser-defs -I /redacted/git/llvm-project/llvm/tools/llvm-lipo -I
> /redacted/git/llvm-project/llvm/include
> /redacted/git/llvm-project/llvm/tools/llvm-lipo/LipoOpts.td
> --write-if-changed -o tools/llvm-lipo/LipoOpts.inc -d
> tools/llvm-lipo/LipoOpts.inc.d
> ==127351==WARNING: MemorySanitizer: use-of-uninitialized-value
> #0 0x1015ae9 in
> llvm::StringRef::split(llvm::SmallVectorImpl&, char, int,
> bool) const
> /redacted/git/llvm-project/llvm/build-msan/../lib/Support/StringRef.cpp:348:3
> #1 0x102e1d5 in llvm::Triple::Triple(llvm::Twine const&)
> /redacted/git/llvm-project/llvm/build-msan/../lib/Support/Triple.cpp:731:19
> #2 0x107dd7d in llvm::sys::getProcessTriple()
> /redacted/git/llvm-project/llvm/build-msan/../lib/Support/Host.cpp:1532:10
> #3 0xf873d7 in ParseCommandLineOptions
> /redacted/git/llvm-project/llvm/build-msan/../lib/Support/CommandLine.cpp:1267:17
> #4 0xf873d7 in llvm::cl::ParseCommandLineOptions(int, char const*
> const*, llvm::StringRef, llvm::raw_ostream*, char const*, bool)
> /redacted/git/llvm-project/llvm/build-msan/../lib/Support/CommandLine.cpp:1242:24
> #5 0xef2ea7 in main
> /redacted/git/llvm-project/llvm/build-msan/../utils/TableGen/TableGen.cpp:267:3
> #6 0x7f6202abf52a in __libc_start_main
> (/lib/x86_64-linux-gnu/libc.so.6+0x2352a)
> #7 0x42d4a9 in _start
> (/redacted/git/llvm-project/llvm/build-msan/bin/llvm-tblgen+0x42d4a9)
>   Uninitialized value was stored to memory at
> #0 0x102ecc6 in StringRef
> /redacted/git/llvm-project/llvm/build-msan/../include/llvm/ADT/StringRef.h:111:27
> #1 0x102ecc6 in llvm::Triple::Triple(llvm::Twine const&)
> /redacted/git/llvm-project/llvm/build-msan/../lib/Support/Triple.cpp:731:3
> #2 0x107dd7d in llvm::sys::getProcessTriple()
> /redacted/git/llvm-project/llvm/build-msan/../lib/Support/Host.cpp:1532:10
> #3 0xf873d7 in ParseCommandLineOptions
> /redacted/git/llvm-project/llvm/build-msan/../lib/Support/CommandLine.cpp:1267:17
> #4 0xf873d7 in llvm::cl::ParseCommandLineOptions(int, char const*
> const*, llvm::StringRef, llvm::raw_ostream*, char const*, bool)
> /redacted/git/llvm-project/llvm/build-msan/../lib/Support/CommandLine.cpp:1242:24
> #5 0xef2ea7 in main
> /redacted/git/llvm-project/llvm/build-msan/../utils/TableGen/TableGen.cpp:267:3
> #6 0x7f6202abf52a in __libc_start_main
> (/lib/x86_64-linux-gnu/libc.so.6+0x2352a)
>   Uninitialized value was created by an allocation of 'PT' in the stack
> frame of function '_ZN4llvm3sys16getProcessTripleEv'
> #0 0x107d9a0 in llvm::sys::getProcessTriple()
> /redacted/git/llvm-project/llvm/build-msan/../lib/Support/Host.cpp:1530
>

On Tue, Oct 29, 2019 at 1:32 PM Guillaume Chatelet 
wrote:

> hi Vlad,
>
> I've spend a big part of my day digging into this and I'm less and less
> convinced that my patch broke the builds.
> IIUC the built bots are still failing although my patch has been
> reverted for quite some time now.
>
> Am I missing something?
>
> On Mon, Oct 28, 2019 at 11:24 PM Vlad Tsyrklevich 
> wrote:
>
>> I've reverted this change as it was causing ASan/MSan failures in
>> check-clang, e.g. take a look at the bottom 2 failures here:
>> http://lab.llvm.org:8014/builders/sanitizer-x86_64-linux-bootstrap/builds/124/steps/check-clang%20asan/logs/stdio
>>  or
>> here
>> http://lab.llvm.org:8014/builders/sanitizer-x86_64-linux-fast/builds/126/steps/check-clang%20msan/logs/stdio
>>
>> On Mon, Oct 28, 2019 at 9:30 AM Guillaume Chatelet via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>>
>>> Author: Guillaume Chatelet
>>> Date: 2019-10-28T17:30:11+01:00
>>> New Revision: bd87916109483d33455cbf20da2309197b983cdd
>>>
>>> URL:
>>> https://github.com/llvm/llvm-project/commit/bd87916109483d33455cbf20da2309197b983cdd
>>> DIFF:
>>> https://github.com/llvm/llvm-project/commit/bd87916109483d33455cbf20da2309197b983cdd.diff
>>>
>>> LOG: [clang] Add no_builtin attribute
>>>
>>> Summary:
>>> This is a follow up on https://reviews.llvm.org/D61634
>>> This patch is simpler and only adds the no_builtin attribute.
>>>
>>> Reviewers: tejohnson, courbet, theraven, t.p.northover, jdoerfert
>>>
>>> Subscribers: mgrang, cfe-commits
>>>
>>> Tags: #clang
>>>
>>> Differential Revi

[clang] 98f3151 - [clang] Add no_builtin attribute

2019-10-29 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2019-10-29T15:50:29+01:00
New Revision: 98f3151a7dded8838fafcb5f46e6c8358def96b8

URL: 
https://github.com/llvm/llvm-project/commit/98f3151a7dded8838fafcb5f46e6c8358def96b8
DIFF: 
https://github.com/llvm/llvm-project/commit/98f3151a7dded8838fafcb5f46e6c8358def96b8.diff

LOG: [clang] Add no_builtin attribute

Summary:
This is a follow up on https://reviews.llvm.org/D61634
This patch is simpler and only adds the no_builtin attribute.

Reviewers: tejohnson, courbet, theraven, t.p.northover, jdoerfert

Subscribers: mgrang, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D68028

This is a re-submit after it got reverted in 
https://reviews.llvm.org/rGbd8791610948 since the breakage doesn't seem to come 
from this patch.

Added: 
clang/test/CodeGen/no-builtin.cpp
clang/test/Sema/no-builtin.cpp

Modified: 
clang/include/clang/AST/Decl.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGCall.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index b3e7a570fd6d..16094c0988fa 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2031,6 +2031,10 @@ class FunctionDecl : public DeclaratorDecl,
   ///
   /// This does not determine whether the function has been defined (e.g., in a
   /// previous definition); for that information, use isDefined.
+  ///
+  /// Note: the function declaration does not become a definition until the
+  /// parser reaches the definition, if called before, this function will 
return
+  /// `false`.
   bool isThisDeclarationADefinition() const {
 return isDeletedAsWritten() || isDefaulted() || Body || hasSkippedBody() ||
isLateTemplateParsed() || willHaveBody() || hasDefiningAttr();

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 4557a614d361..d5018f444e1c 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3427,3 +3427,10 @@ def ObjCExternallyRetained : InheritableAttr {
   let Subjects = SubjectList<[NonParmVar, Function, Block, ObjCMethod]>;
   let Documentation = [ObjCExternallyRetainedDocs];
 }
+
+def NoBuiltin : Attr {
+  let Spellings = [Clang<"no_builtin">];
+  let Args = [VariadicStringArgument<"BuiltinNames">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [NoBuiltinDocs];
+}

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 6e79d0bb3631..9d0d27407573 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4413,3 +4413,40 @@ and is not a general mechanism for declaring arbitrary 
aliases for
 clang builtin functions.
   }];
 }
+
+def NoBuiltinDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+.. Note:: This attribute is not yet fully implemented, it is validated but has
+no effect on the generated code.
+
+The ``__attribute__((no_builtin))`` is similar to the ``-fno-builtin`` flag
+except it is specific to the body of a function. The attribute may also be
+applied to a virtual function but has no effect on the behavior of overriding
+functions in a derived class.
+
+It accepts one or more strings corresponding to the specific names of the
+builtins to disable (e.g. "memcpy", "memset").
+If the attribute is used without parameters it will disable all buitins at
+once.
+
+.. code-block:: c++
+
+  // The compiler is not allowed to add any builtin to foo's body.
+  void foo(char* data, size_t count) __attribute__((no_builtin)) {
+// The compiler is not allowed to convert the loop into
+// `__builtin_memset(data, 0xFE, count);`.
+for (size_t i = 0; i < count; ++i)
+  data[i] = 0xFE;
+  }
+
+  // The compiler is not allowed to add the `memcpy` builtin to bar's body.
+  void bar(char* data, size_t count) __attribute__((no_builtin("memcpy"))) {
+// The compiler is allowed to convert the loop into
+// `__builtin_memset(data, 0xFE, count);` but cannot generate any
+// `__builtin_memcpy`
+for (size_t i = 0; i < count; ++i)
+  data[i] = 0xFE;
+  }
+  }];
+}

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c93edb2f91c2..2313c60f006f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3604,6 +3604,15 @@ def err_attribute_overloadable_no_prototype : Error<
 def err_attribute_overloadable_multiple_unmarked_overloads : Error<
   "at most one overload for a given name may lack the 'overloadable' "
   "attribute">;
+def warn_a

[clang] 5607ff1 - Fix missing memcpy builtin on ppc64be

2019-10-29 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2019-10-29T16:35:32+01:00
New Revision: 5607ff12fad9a54728a3cda0eacaffee02e4b434

URL: 
https://github.com/llvm/llvm-project/commit/5607ff12fad9a54728a3cda0eacaffee02e4b434
DIFF: 
https://github.com/llvm/llvm-project/commit/5607ff12fad9a54728a3cda0eacaffee02e4b434.diff

LOG: Fix missing memcpy builtin on ppc64be
See D68028

Added: 


Modified: 
clang/test/CodeGen/no-builtin.cpp
clang/test/Sema/no-builtin.cpp

Removed: 




diff  --git a/clang/test/CodeGen/no-builtin.cpp 
b/clang/test/CodeGen/no-builtin.cpp
index 3c5d681282da..24df100d8717 100644
--- a/clang/test/CodeGen/no-builtin.cpp
+++ b/clang/test/CodeGen/no-builtin.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -S -emit-llvm -o - %s | FileCheck 
%s
+// UNSUPPORTED: ppc64be
 
 // CHECK-LABEL: define void @foo_no_mempcy() #0
 extern "C" void foo_no_mempcy() __attribute__((no_builtin("memcpy"))) {}

diff  --git a/clang/test/Sema/no-builtin.cpp b/clang/test/Sema/no-builtin.cpp
index 40781abd3037..8908f38333bd 100644
--- a/clang/test/Sema/no-builtin.cpp
+++ b/clang/test/Sema/no-builtin.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
+// UNSUPPORTED: ppc64be
 
 /// Prevent use of all builtins.
 void valid_attribute_all_1() __attribute__((no_builtin)) {}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1c85a2e - isBuiltinFunc() uses StringRef instead of const char*

2019-10-29 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2019-10-29T17:36:55+01:00
New Revision: 1c85a2e8dc7e76761d301f9a35374e0aafc757ec

URL: 
https://github.com/llvm/llvm-project/commit/1c85a2e8dc7e76761d301f9a35374e0aafc757ec
DIFF: 
https://github.com/llvm/llvm-project/commit/1c85a2e8dc7e76761d301f9a35374e0aafc757ec.diff

LOG: isBuiltinFunc() uses StringRef instead of const char*

Summary: This prevents a bug when passing nullptr, StringRef ctor would call 
strlen(nullptr).

Reviewers: vlad.tsyrklevich

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69569

Added: 


Modified: 
clang/include/clang/Basic/Builtins.h
clang/lib/Basic/Builtins.cpp
clang/lib/Sema/SemaDeclAttr.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index fed0dae20193..af07d4241438 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -224,7 +224,7 @@ class Context {
 
   /// Returns true if this is a libc/libm function without the '__builtin_'
   /// prefix.
-  static bool isBuiltinFunc(const char *Name);
+  static bool isBuiltinFunc(llvm::StringRef Name);
 
   /// Returns true if this is a builtin that can be redeclared.  Returns true
   /// for non-builtins.

diff  --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp
index d23c280d4758..0cd89df41b67 100644
--- a/clang/lib/Basic/Builtins.cpp
+++ b/clang/lib/Basic/Builtins.cpp
@@ -47,8 +47,7 @@ void Builtin::Context::InitializeTarget(const TargetInfo 
&Target,
 AuxTSRecords = AuxTarget->getTargetBuiltins();
 }
 
-bool Builtin::Context::isBuiltinFunc(const char *Name) {
-  StringRef FuncName(Name);
+bool Builtin::Context::isBuiltinFunc(llvm::StringRef FuncName) {
   for (unsigned i = Builtin::NotBuiltin + 1; i != Builtin::FirstTSBuiltin; ++i)
 if (FuncName.equals(BuiltinInfo[i].Name))
   return strchr(BuiltinInfo[i].Attributes, 'f') != nullptr;

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 99eb23c3fe61..7f68d2014916 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1096,7 +1096,7 @@ static void handleNoBuiltinAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   if (!S.checkStringLiteralArgumentAttr(AL, I, BuiltinName, &LiteralLoc))
 return;
 
-  if (Builtin::Context::isBuiltinFunc(BuiltinName.data()))
+  if (Builtin::Context::isBuiltinFunc(BuiltinName))
 AddBuiltinName(BuiltinName);
   else
 S.Diag(LiteralLoc, 
diag::warn_attribute_no_builtin_invalid_builtin_name)



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 12c8e36 - [Clang][Sema] Use of incorrect __has_feature vs __has_builtin

2020-06-18 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2020-06-18T09:00:12Z
New Revision: 12c8e3632edda3bc640867ba326b52b5b2220a57

URL: 
https://github.com/llvm/llvm-project/commit/12c8e3632edda3bc640867ba326b52b5b2220a57
DIFF: 
https://github.com/llvm/llvm-project/commit/12c8e3632edda3bc640867ba326b52b5b2220a57.diff

LOG: [Clang][Sema] Use of incorrect __has_feature vs __has_builtin

Added: 


Modified: 
clang/test/Sema/builtins-memcpy-inline.cpp

Removed: 




diff  --git a/clang/test/Sema/builtins-memcpy-inline.cpp 
b/clang/test/Sema/builtins-memcpy-inline.cpp
index 5e03a975a71b..81b11fc021ff 100644
--- a/clang/test/Sema/builtins-memcpy-inline.cpp
+++ b/clang/test/Sema/builtins-memcpy-inline.cpp
@@ -2,7 +2,7 @@
 
 #define NULL ((char *)0)
 
-#if __has_feature(__builtin_memcpy_inline)
+#if __has_builtin(__builtin_memcpy_inline)
 #warning defined as expected
 // expected-warning@-1 {{defined as expected}}
 #endif



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] [clang-tools-extra] [flang] [compiler-rt] [llvm] [libc][NFC] Remove __support/bit.h and use __support/CPP/bit.h instead (PR #73939)

2023-12-05 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet updated 
https://github.com/llvm/llvm-project/pull/73939

>From 651cdece9397cf643cfafef7c65f4b8f44148d29 Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet 
Date: Thu, 30 Nov 2023 13:53:28 +
Subject: [PATCH 1/3] [libc][NFC] Remove __support/bit.h and use
 __support/CPP/bit.h instead

---
 libc/src/__support/CMakeLists.txt |   8 +-
 libc/src/__support/FPUtil/CMakeLists.txt  |   2 -
 libc/src/__support/FPUtil/FPBits.h|   3 +-
 libc/src/__support/FPUtil/Hypot.h |  11 +-
 .../__support/FPUtil/generic/CMakeLists.txt   |   5 +-
 libc/src/__support/FPUtil/generic/FMA.h   |   8 +-
 libc/src/__support/FPUtil/generic/FMod.h  |   8 +-
 libc/src/__support/FPUtil/generic/sqrt.h  |  13 +-
 .../FPUtil/generic/sqrt_80_bit_long_double.h  |   6 +-
 libc/src/__support/HashTable/CMakeLists.txt   |  12 +-
 libc/src/__support/HashTable/bitmask.h|   4 +-
 libc/src/__support/HashTable/table.h  |   7 +-
 libc/src/__support/UInt.h |   4 +-
 libc/src/__support/bit.h  | 117 --
 libc/src/__support/hash.h |   8 +-
 libc/src/__support/integer_utils.h|   1 -
 libc/src/__support/memory_size.h  |  17 ++-
 libc/src/__support/str_to_float.h |   5 +-
 libc/src/math/generic/CMakeLists.txt  |   1 -
 libc/src/math/generic/powf.cpp|   5 +-
 libc/src/string/memory_utils/op_builtin.h |  22 ++--
 libc/src/string/memory_utils/utils.h  |  47 ++-
 libc/test/src/__support/CMakeLists.txt|  13 --
 .../src/__support/HashTable/table_test.cpp|   3 +-
 libc/test/src/__support/bit_test.cpp  |  67 --
 libc/test/src/__support/memory_size_test.cpp  |  11 ++
 libc/test/src/search/hsearch_test.cpp |   4 +-
 .../src/string/memory_utils/utils_test.cpp|  60 -
 .../llvm-project-overlay/libc/BUILD.bazel |  19 +--
 .../libc/test/src/__support/BUILD.bazel   |   6 -
 .../test/src/math/libc_math_test_rules.bzl|   1 -
 31 files changed, 105 insertions(+), 393 deletions(-)
 delete mode 100644 libc/src/__support/bit.h
 delete mode 100644 libc/test/src/__support/bit_test.cpp

diff --git a/libc/src/__support/CMakeLists.txt 
b/libc/src/__support/CMakeLists.txt
index a76b22960f5a5..03305a2f06aae 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -140,13 +140,13 @@ add_header_library(
 .str_to_num_result
 .uint128
 libc.src.__support.common
+libc.src.__support.CPP.bit
 libc.src.__support.CPP.limits
 libc.src.__support.CPP.optional
 libc.src.__support.FPUtil.dyadic_float
 libc.src.__support.FPUtil.fenv_impl
 libc.src.__support.FPUtil.fp_bits
 libc.src.__support.FPUtil.rounding_mode
-libc.src.__support.bit
 libc.src.errno.errno
 )
 
@@ -194,9 +194,9 @@ add_header_library(
   HDRS
 integer_utils.h
   DEPENDS
-.bit
 .number_pair
 libc.src.__support.common
+libc.src.__support.CPP.bit
 libc.src.__support.CPP.type_traits
 )
 
@@ -205,11 +205,11 @@ add_header_library(
   HDRS
 UInt.h
   DEPENDS
-.bit
 .integer_utils
 .math_extras
 .number_pair
 libc.src.__support.CPP.array
+libc.src.__support.CPP.bit
 libc.src.__support.CPP.type_traits
 libc.src.__support.macros.optimization
 )
@@ -236,8 +236,8 @@ add_header_library(
   HDRS
 hash.h
   DEPENDS
-.bit
 .uint128
+libc.src.__support.CPP.bit
 libc.src.__support.macros.attributes
 )
 
diff --git a/libc/src/__support/FPUtil/CMakeLists.txt 
b/libc/src/__support/FPUtil/CMakeLists.txt
index 58a182eaa797b..3d6d712fc2058 100644
--- a/libc/src/__support/FPUtil/CMakeLists.txt
+++ b/libc/src/__support/FPUtil/CMakeLists.txt
@@ -41,7 +41,6 @@ add_header_library(
 libc.src.__support.common
 libc.src.__support.CPP.bit
 libc.src.__support.CPP.type_traits
-libc.src.__support.bit
 )
 
 add_header_library(
@@ -146,7 +145,6 @@ add_header_library(
 libc.src.__support.common
 libc.src.__support.CPP.bit
 libc.src.__support.CPP.type_traits
-libc.src.__support.bit
 libc.src.__support.uint128
 )
 
diff --git a/libc/src/__support/FPUtil/FPBits.h 
b/libc/src/__support/FPUtil/FPBits.h
index 76a9fc6d772bf..dba0c7e0745c2 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -11,7 +11,6 @@
 
 #include "src/__support/CPP/bit.h"
 #include "src/__support/CPP/type_traits.h"
-#include "src/__support/bit.h"
 #include "src/__support/common.h"
 #include "src/__support/macros/attributes.h" // LIBC_INLINE
 
@@ -222,7 +221,7 @@ template  struct FPBits {
   LIBC_INLINE static constexpr FPBits make_value(UIntType number, int ep) {
 FPBits result;
 // offset: +1 for sign, but -1 for implicit first bit
-int lz = unsafe_clz(number) - FloatProp::EXPONENT_WIDTH;
+int lz = cpp::countl_zero(number) - FloatProp::EXPONENT_WIDTH;
 num

[clang] [libc] [clang-tools-extra] [flang] [compiler-rt] [llvm] [libc][NFC] Remove __support/bit.h and use __support/CPP/bit.h instead (PR #73939)

2023-12-05 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet closed 
https://github.com/llvm/llvm-project/pull/73939
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [mlir] [llvm][TypeSize] Fix addition/subtraction in TypeSize. (PR #72979)

2023-11-21 Thread Guillaume Chatelet via cfe-commits

gchatelet wrote:

The static functions renaming is going to produce a lot of noise but I guess 
this is too late already...
Shall we revert to keep the change minimal? @nikic @paulwalker-arm WDYT ?


https://github.com/llvm/llvm-project/pull/72979
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [mlir] [llvm] [llvm][TypeSize] Fix addition/subtraction in TypeSize. (PR #72979)

2023-11-21 Thread Guillaume Chatelet via cfe-commits

gchatelet wrote:

> > The static functions renaming is going to produce a lot of noise but I 
> > guess this is too late already... Shall we revert to keep the change 
> > minimal? @nikic @paulwalker-arm WDYT ?
> 
> For my money the functions were originally named correctly and then 
> erroneously changed to (a) diverge from the coding standard, and (b) 
> unknowingly introduced a bug caused by the new naming. For both reasons I'm 
> happy to revert to the original naming via this patch.

That would be [my patch](https://reviews.llvm.org/D140263) indeed. Let's revert 
to the original naming via this patch.

https://github.com/llvm/llvm-project/pull/72979
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[mlir] [clang] [llvm] [llvm][TypeSize] Fix addition/subtraction in TypeSize. (PR #72979)

2023-11-21 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet approved this pull request.


https://github.com/llvm/llvm-project/pull/72979
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [lldb] [libc] [clang] [clang-tools-extra] [libcxxabi] [llvm] [compiler-rt] [libcxx] [libunwind] [lld] [libc] Add more functions in CPP/bit.h (PR #73814)

2023-11-30 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet updated 
https://github.com/llvm/llvm-project/pull/73814

>From bdd0a0855c0dd98c93977db6982e480ab270b3cd Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet 
Date: Wed, 29 Nov 2023 16:29:12 +
Subject: [PATCH 1/7] [libc] Add more functions in CPP/bit.h

---
 libc/src/__support/CPP/CMakeLists.txt |   1 +
 libc/src/__support/CPP/bit.h  | 242 --
 libc/src/__support/CPP/limits.h   |  18 +-
 libc/test/src/__support/CPP/CMakeLists.txt|  11 +
 libc/test/src/__support/CPP/bit_test.cpp  | 216 
 .../llvm-project-overlay/libc/BUILD.bazel |   1 +
 .../libc/test/src/__support/CPP/BUILD.bazel   |   9 +
 7 files changed, 478 insertions(+), 20 deletions(-)
 create mode 100644 libc/test/src/__support/CPP/bit_test.cpp

diff --git a/libc/src/__support/CPP/CMakeLists.txt 
b/libc/src/__support/CPP/CMakeLists.txt
index 10bcebf9b04f61d..5c47b2a815356b9 100644
--- a/libc/src/__support/CPP/CMakeLists.txt
+++ b/libc/src/__support/CPP/CMakeLists.txt
@@ -15,6 +15,7 @@ add_header_library(
   HDRS
 bit.h
   DEPENDS
+.limits
 .type_traits
 libc.src.__support.macros.attributes
 libc.src.__support.macros.config
diff --git a/libc/src/__support/CPP/bit.h b/libc/src/__support/CPP/bit.h
index f6f3131c1ccfd81..f744d804398e213 100644
--- a/libc/src/__support/CPP/bit.h
+++ b/libc/src/__support/CPP/bit.h
@@ -1,57 +1,261 @@
-//===-- Freestanding version of bit_cast  ---*- C++ 
-*-===//
+//===-- Implementation of the C++20 bit header  -*- C++ 
-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 
//===--===//
+// This is inspired from LLVM ADT/bit.h header.
 
 #ifndef LLVM_LIBC_SRC___SUPPORT_CPP_BIT_H
 #define LLVM_LIBC_SRC___SUPPORT_CPP_BIT_H
 
+#include "src/__support/CPP/limits.h" // numeric_limits
 #include "src/__support/CPP/type_traits.h"
 #include "src/__support/macros/attributes.h"
 #include "src/__support/macros/config.h" // LIBC_HAS_BUILTIN
 #include "src/__support/macros/sanitizer.h"
 
-namespace LIBC_NAMESPACE::cpp {
+#include 
 
-#if LIBC_HAS_BUILTIN(__builtin_bit_cast)
-#define LLVM_LIBC_HAS_BUILTIN_BIT_CAST
-#endif
+namespace LIBC_NAMESPACE::cpp {
 
 #if LIBC_HAS_BUILTIN(__builtin_memcpy_inline)
 #define LLVM_LIBC_HAS_BUILTIN_MEMCPY_INLINE
 #endif
 
-// This function guarantees the bitcast to be optimized away by the compiler 
for
-// GCC >= 8 and Clang >= 6.
-template 
+// This implementation of bit_cast requires trivially-constructible To, to 
avoid
+// UB in the implementation.
+template <
+typename To, typename From,
+typename = cpp::enable_if_t,
+typename = cpp::enable_if_t::value>,
+typename = cpp::enable_if_t::value>,
+typename = cpp::enable_if_t::value>>
 LIBC_INLINE constexpr To bit_cast(const From &from) {
-  static_assert(sizeof(To) == sizeof(From), "To and From must be of same 
size");
-  static_assert(cpp::is_trivially_copyable::value &&
-cpp::is_trivially_copyable::value,
-"Cannot bit-cast instances of non-trivially copyable 
classes.");
   MSAN_UNPOISON(&from, sizeof(From));
-#if defined(LLVM_LIBC_HAS_BUILTIN_BIT_CAST)
+#if LIBC_HAS_BUILTIN(__builtin_bit_cast)
   return __builtin_bit_cast(To, from);
 #else
-  static_assert(cpp::is_trivially_constructible::value,
-"This implementation additionally requires destination type to 
"
-"be trivially constructible");
   To to;
   char *dst = reinterpret_cast(&to);
   const char *src = reinterpret_cast(&from);
-#if defined(LLVM_LIBC_HAS_BUILTIN_MEMCPY_INLINE)
+#if LIBC_HAS_BUILTIN(__builtin_memcpy_inline)
   __builtin_memcpy_inline(dst, src, sizeof(To));
 #else
   for (unsigned i = 0; i < sizeof(To); ++i)
 dst[i] = src[i];
-#endif // defined(LLVM_LIBC_HAS_BUILTIN_MEMCPY_INLINE)
+#endif // LIBC_HAS_BUILTIN(__builtin_memcpy_inline)
   return to;
-#endif // defined(LLVM_LIBC_HAS_BUILTIN_BIT_CAST)
+#endif // LIBC_HAS_BUILTIN(__builtin_bit_cast)
+}
+
+template >>
+[[nodiscard]] LIBC_INLINE constexpr bool has_single_bit(T value) {
+  return (value != 0) && ((value & (value - 1)) == 0);
+}
+
+// A temporary macro to add template function specialization when compiler
+// builtin is available.
+#define ADD_SPECIALIZATION(NAME, TYPE, BUILTIN)
\
+  template <> [[nodiscard]] LIBC_INLINE constexpr int NAME(TYPE value) { 
\
+static_assert(cpp::is_unsigned_v);   
\
+return value == 0 ? cpp::numeric_limits::digits : BUILTIN(value);
\
+  }
+
+/// Count number of 0's from the least significant bit to the most
+///   stopping at the first 1.
+///
+/// Only unsigned integral types are allowed.
+///
+/// Returns cpp::numeric_limits::dig

[compiler-rt] [llvm] [libcxxabi] [clang-tools-extra] [clang] [libunwind] [libc] [flang] [lldb] [libcxx] [lld] [libc] Add more functions in CPP/bit.h (PR #73814)

2023-11-30 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet updated 
https://github.com/llvm/llvm-project/pull/73814

>From bdd0a0855c0dd98c93977db6982e480ab270b3cd Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet 
Date: Wed, 29 Nov 2023 16:29:12 +
Subject: [PATCH 1/8] [libc] Add more functions in CPP/bit.h

---
 libc/src/__support/CPP/CMakeLists.txt |   1 +
 libc/src/__support/CPP/bit.h  | 242 --
 libc/src/__support/CPP/limits.h   |  18 +-
 libc/test/src/__support/CPP/CMakeLists.txt|  11 +
 libc/test/src/__support/CPP/bit_test.cpp  | 216 
 .../llvm-project-overlay/libc/BUILD.bazel |   1 +
 .../libc/test/src/__support/CPP/BUILD.bazel   |   9 +
 7 files changed, 478 insertions(+), 20 deletions(-)
 create mode 100644 libc/test/src/__support/CPP/bit_test.cpp

diff --git a/libc/src/__support/CPP/CMakeLists.txt 
b/libc/src/__support/CPP/CMakeLists.txt
index 10bcebf9b04f61d..5c47b2a815356b9 100644
--- a/libc/src/__support/CPP/CMakeLists.txt
+++ b/libc/src/__support/CPP/CMakeLists.txt
@@ -15,6 +15,7 @@ add_header_library(
   HDRS
 bit.h
   DEPENDS
+.limits
 .type_traits
 libc.src.__support.macros.attributes
 libc.src.__support.macros.config
diff --git a/libc/src/__support/CPP/bit.h b/libc/src/__support/CPP/bit.h
index f6f3131c1ccfd81..f744d804398e213 100644
--- a/libc/src/__support/CPP/bit.h
+++ b/libc/src/__support/CPP/bit.h
@@ -1,57 +1,261 @@
-//===-- Freestanding version of bit_cast  ---*- C++ 
-*-===//
+//===-- Implementation of the C++20 bit header  -*- C++ 
-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 
//===--===//
+// This is inspired from LLVM ADT/bit.h header.
 
 #ifndef LLVM_LIBC_SRC___SUPPORT_CPP_BIT_H
 #define LLVM_LIBC_SRC___SUPPORT_CPP_BIT_H
 
+#include "src/__support/CPP/limits.h" // numeric_limits
 #include "src/__support/CPP/type_traits.h"
 #include "src/__support/macros/attributes.h"
 #include "src/__support/macros/config.h" // LIBC_HAS_BUILTIN
 #include "src/__support/macros/sanitizer.h"
 
-namespace LIBC_NAMESPACE::cpp {
+#include 
 
-#if LIBC_HAS_BUILTIN(__builtin_bit_cast)
-#define LLVM_LIBC_HAS_BUILTIN_BIT_CAST
-#endif
+namespace LIBC_NAMESPACE::cpp {
 
 #if LIBC_HAS_BUILTIN(__builtin_memcpy_inline)
 #define LLVM_LIBC_HAS_BUILTIN_MEMCPY_INLINE
 #endif
 
-// This function guarantees the bitcast to be optimized away by the compiler 
for
-// GCC >= 8 and Clang >= 6.
-template 
+// This implementation of bit_cast requires trivially-constructible To, to 
avoid
+// UB in the implementation.
+template <
+typename To, typename From,
+typename = cpp::enable_if_t,
+typename = cpp::enable_if_t::value>,
+typename = cpp::enable_if_t::value>,
+typename = cpp::enable_if_t::value>>
 LIBC_INLINE constexpr To bit_cast(const From &from) {
-  static_assert(sizeof(To) == sizeof(From), "To and From must be of same 
size");
-  static_assert(cpp::is_trivially_copyable::value &&
-cpp::is_trivially_copyable::value,
-"Cannot bit-cast instances of non-trivially copyable 
classes.");
   MSAN_UNPOISON(&from, sizeof(From));
-#if defined(LLVM_LIBC_HAS_BUILTIN_BIT_CAST)
+#if LIBC_HAS_BUILTIN(__builtin_bit_cast)
   return __builtin_bit_cast(To, from);
 #else
-  static_assert(cpp::is_trivially_constructible::value,
-"This implementation additionally requires destination type to 
"
-"be trivially constructible");
   To to;
   char *dst = reinterpret_cast(&to);
   const char *src = reinterpret_cast(&from);
-#if defined(LLVM_LIBC_HAS_BUILTIN_MEMCPY_INLINE)
+#if LIBC_HAS_BUILTIN(__builtin_memcpy_inline)
   __builtin_memcpy_inline(dst, src, sizeof(To));
 #else
   for (unsigned i = 0; i < sizeof(To); ++i)
 dst[i] = src[i];
-#endif // defined(LLVM_LIBC_HAS_BUILTIN_MEMCPY_INLINE)
+#endif // LIBC_HAS_BUILTIN(__builtin_memcpy_inline)
   return to;
-#endif // defined(LLVM_LIBC_HAS_BUILTIN_BIT_CAST)
+#endif // LIBC_HAS_BUILTIN(__builtin_bit_cast)
+}
+
+template >>
+[[nodiscard]] LIBC_INLINE constexpr bool has_single_bit(T value) {
+  return (value != 0) && ((value & (value - 1)) == 0);
+}
+
+// A temporary macro to add template function specialization when compiler
+// builtin is available.
+#define ADD_SPECIALIZATION(NAME, TYPE, BUILTIN)
\
+  template <> [[nodiscard]] LIBC_INLINE constexpr int NAME(TYPE value) { 
\
+static_assert(cpp::is_unsigned_v);   
\
+return value == 0 ? cpp::numeric_limits::digits : BUILTIN(value);
\
+  }
+
+/// Count number of 0's from the least significant bit to the most
+///   stopping at the first 1.
+///
+/// Only unsigned integral types are allowed.
+///
+/// Returns cpp::numeric_limits::dig

[compiler-rt] [llvm] [libcxxabi] [clang-tools-extra] [clang] [libunwind] [libc] [flang] [lldb] [libcxx] [lld] [libc] Add more functions in CPP/bit.h (PR #73814)

2023-11-30 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet closed 
https://github.com/llvm/llvm-project/pull/73814
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [libc] [llvm] [libc] Fix buggy AVX2 / AVX512 `memcmp` (PR #77081)

2024-01-11 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet updated 
https://github.com/llvm/llvm-project/pull/77081

>From fb8dbd55aacb3a25678b8092a11dd4e562857344 Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet 
Date: Fri, 5 Jan 2024 11:01:30 +
Subject: [PATCH 1/6] [libc] Fix buggy AVX2 `memcmp`

Fixes 77080.
---
 libc/src/string/memory_utils/op_x86.h | 33 ++-
 libc/test/src/string/memcmp_test.cpp  |  7 ++
 2 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/libc/src/string/memory_utils/op_x86.h 
b/libc/src/string/memory_utils/op_x86.h
index 1a20659c178cd1..23e6b897997e90 100644
--- a/libc/src/string/memory_utils/op_x86.h
+++ b/libc/src/string/memory_utils/op_x86.h
@@ -129,7 +129,8 @@ LIBC_INLINE __m128i bytewise_reverse(__m128i value) {
   8, 9, 10, 11, 12, 13, 14, 15));
 }
 LIBC_INLINE uint16_t big_endian_cmp_mask(__m128i max, __m128i value) {
-  return 
static_cast(_mm_movemask_epi8(bytewise_reverse(_mm_cmpeq_epi8(max, 
value;
+  return static_cast(
+  _mm_movemask_epi8(bytewise_reverse(_mm_cmpeq_epi8(max, value;
 }
 template <> LIBC_INLINE bool eq<__m128i>(CPtr p1, CPtr p2, size_t offset) {
   const auto a = load<__m128i>(p1, offset);
@@ -181,11 +182,31 @@ LIBC_INLINE __m256i bytewise_max(__m256i a, __m256i b) {
   return _mm256_max_epu8(a, b);
 }
 LIBC_INLINE __m256i bytewise_reverse(__m256i value) {
-  return _mm256_shuffle_epi8(value,
- _mm256_set_epi8(0, 1, 2, 3, 4, 5, 6, 7, //
- 8, 9, 10, 11, 12, 13, 14, 15,   //
- 16, 17, 18, 19, 20, 21, 22, 23, //
- 24, 25, 26, 27, 28, 29, 30, 31));
+  const __m256i indices = _mm256_set_epi8(0, 1, 2, 3, 4, 5, 6, 7, //
+  8, 9, 10, 11, 12, 13, 14, 15,   //
+  16, 17, 18, 19, 20, 21, 22, 23, //
+  24, 25, 26, 27, 28, 29, 30, 31);
+#if defined(__AVX512VBMI__) && defined(__AVX512VL__)
+  // AVX512 allows full __m256i byte permutation.
+  // ymm = ymm[31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,
+  //   15,14,13,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
+  return _mm256_permutexvar_epi8(value, indices);
+#else
+  // We can't byte-reverse __m256i in a single instruction with AVX2.
+  // '_mm256_shuffle_epi8' can only shuffle within each xmm lane
+  // leading to:
+  // ymm = ymm[15,14,13,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
+  //   31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16]
+  const __m256i tmp = _mm256_shuffle_epi8(value, indices);
+  // Then we shuffle accross lanes using 64 bit values.
+  // ymm = ymm[2,3,0,1]
+  // Leading to a fully reversed vector
+  // ymm = ymm[31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,
+  //   15,14,13,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
+  // The immediate encodes the 64 bit word indices  :1, 0, 3, 2.
+  // Each index is encoded with 2 bits  : 0b01'00'11'10.
+  return _mm256_permute4x64_epi64(tmp, 0b01'00'11'10);
+#endif
 }
 LIBC_INLINE uint32_t big_endian_cmp_mask(__m256i max, __m256i value) {
   return _mm256_movemask_epi8(bytewise_reverse(_mm256_cmpeq_epi8(max, value)));
diff --git a/libc/test/src/string/memcmp_test.cpp 
b/libc/test/src/string/memcmp_test.cpp
index 03a0ac1c0ba655..a69257704a64a2 100644
--- a/libc/test/src/string/memcmp_test.cpp
+++ b/libc/test/src/string/memcmp_test.cpp
@@ -37,6 +37,13 @@ TEST(LlvmLibcMemcmpTest, LhsAfterRhsLexically) {
   EXPECT_GT(LIBC_NAMESPACE::memcmp(lhs, rhs, 2), 0);
 }
 
+TEST(LlvmLibcMemcmpTest, Issue77080) {
+  // https://github.com/llvm/llvm-project/issues/77080
+  constexpr char lhs[35] = "1.069cd68bbe76eb2143a3284d27ebe220";
+  constexpr char rhs[35] = "1.0500185b5d966a544e2d0fa40701b0f3";
+  EXPECT_GT(LIBC_NAMESPACE::memcmp(lhs, rhs, 34), 0);
+}
+
 // Adapt CheckMemcmp signature to memcmp.
 static inline int Adaptor(cpp::span p1, cpp::span p2, size_t size) 
{
   return LIBC_NAMESPACE::memcmp(p1.begin(), p2.begin(), size);

>From 04891668ef388ed354d9a18969ada20d54371ce6 Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet 
Date: Mon, 8 Jan 2024 08:51:12 +
Subject: [PATCH 2/6] Make test clearer

---
 libc/test/src/string/memcmp_test.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/test/src/string/memcmp_test.cpp 
b/libc/test/src/string/memcmp_test.cpp
index a69257704a64a2..ca7a5c7ce37023 100644
--- a/libc/test/src/string/memcmp_test.cpp
+++ b/libc/test/src/string/memcmp_test.cpp
@@ -41,7 +41,7 @@ TEST(LlvmLibcMemcmpTest, Issue77080) {
   // https://github.com/llvm/llvm-project/issues/77080
   constexpr char lhs[35] = "1.069cd68bbe76eb2143a3284d27ebe220";
   constexpr char rhs[35] = "1.0500185b5d966a544e2d0fa40701b0f3";
-  EXPECT_GT(LIBC_NAMESPACE::memcmp(lhs, rhs, 34), 0);
+  ASSERT_GE(LIBC_NAMESPACE::memcmp(lhs, rhs, 34), 1);
 }
 
 // Adapt C

[clang] [clang-tools-extra] [llvm] [libc] [libc] Fix buggy AVX2 / AVX512 `memcmp` (PR #77081)

2024-01-11 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet closed 
https://github.com/llvm/llvm-project/pull/77081
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4b3a27e - Add validation for number of arguments of __builtin_memcpy_inline

2022-03-18 Thread Guillaume Chatelet via cfe-commits

Author: Roy Jacobson
Date: 2022-03-18T14:03:25Z
New Revision: 4b3a27e2e026f9be703c1bdcb396c10559a87347

URL: 
https://github.com/llvm/llvm-project/commit/4b3a27e2e026f9be703c1bdcb396c10559a87347
DIFF: 
https://github.com/llvm/llvm-project/commit/4b3a27e2e026f9be703c1bdcb396c10559a87347.diff

LOG: Add validation for number of arguments of __builtin_memcpy_inline

__builtin_memcpy_inline doesn't use the usual builtin argument validation code,
so it crashed when receiving wrong number of argument. Add the missing 
validation
check.

Open issue: https://github.com/llvm/llvm-project/issues/52949

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D121965

Committed by gchatelet on behalf of "Roy Jacobson "

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/builtins-memcpy-inline.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2d2250771eb6e..e02104b4699e1 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -1679,7 +1679,10 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 if ((ICEArguments & (1 << ArgNo)) == 0) continue;
 
 llvm::APSInt Result;
-if (SemaBuiltinConstantArg(TheCall, ArgNo, Result))
+// If we don't have enough arguments, continue so we can issue better
+// diagnostic in checkArgCount(...)
+if (ArgNo < TheCall->getNumArgs() &&
+SemaBuiltinConstantArg(TheCall, ArgNo, Result))
   return true;
 ICEArguments &= ~(1 << ArgNo);
   }
@@ -1943,6 +1946,8 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
   case Builtin::BI__builtin_nontemporal_store:
 return SemaBuiltinNontemporalOverloaded(TheCallResult);
   case Builtin::BI__builtin_memcpy_inline: {
+if (checkArgCount(*this, TheCall, 3))
+  return ExprError();
 auto ArgArrayConversionFailed = [&](unsigned Arg) {
   ExprResult ArgExpr =
   DefaultFunctionArrayLvalueConversion(TheCall->getArg(Arg));

diff  --git a/clang/test/Sema/builtins-memcpy-inline.cpp 
b/clang/test/Sema/builtins-memcpy-inline.cpp
index 30bc636c78393..ab0a8700a6c98 100644
--- a/clang/test/Sema/builtins-memcpy-inline.cpp
+++ b/clang/test/Sema/builtins-memcpy-inline.cpp
@@ -42,3 +42,8 @@ void test_memcpy_inline_implicit_conversion(void *ptr) {
   __builtin_memcpy_inline(ptr, a, 5);
   __builtin_memcpy_inline(a, ptr, 5);
 }
+
+void test_memcpy_inline_num_args(void *dst, void *src) {
+ __builtin_memcpy_inline(); // expected-error {{too few arguments to function 
call}}
+ __builtin_memcpy_inline(dst, src, 4, NULL); // expected-error {{too many 
arguments to function call}}
+}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [libc] [llvm] [clang-tools-extra] [clang] [libc] `FPRep` builders return `FPRep` instead of raw `StorageType` (PR #78588)

2024-01-22 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet updated 
https://github.com/llvm/llvm-project/pull/78588

>From 49ba96c8aa51fb56a5bf96a1e97fef48bcc42f09 Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet 
Date: Thu, 18 Jan 2024 14:42:54 +
Subject: [PATCH 1/3] [libc] `FPRep` builders return `FPRep` instead of raw
 `StorageType`

---
 libc/src/__support/FPUtil/FPBits.h|  68 
 .../test/src/__support/FPUtil/fpbits_test.cpp | 163 +-
 2 files changed, 120 insertions(+), 111 deletions(-)

diff --git a/libc/src/__support/FPUtil/FPBits.h 
b/libc/src/__support/FPUtil/FPBits.h
index 3ee6289b749648..5df49350e3744e 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -332,7 +332,10 @@ struct FPRepBase : public internal::FPLayout {
   mask_trailing_ones();
 
   // The floating point number representation as an unsigned integer.
-  StorageType bits = 0;
+  StorageType bits;
+
+  LIBC_INLINE constexpr FPRepBase() : bits(0) {}
+  LIBC_INLINE constexpr FPRepBase(StorageType value) : bits(value) {}
 
 public:
   LIBC_INLINE constexpr Sign sign() const {
@@ -418,6 +421,7 @@ template  struct FPRep : public 
FPRepBase {
   using UP::exp_bits;
   using UP::exp_sig_bits;
   using UP::sig_bits;
+  using UP::UP;
 
 public:
   LIBC_INLINE constexpr bool is_nan() const {
@@ -450,37 +454,35 @@ template  struct FPRep : public 
FPRepBase {
 return is_finite() && !is_subnormal();
   }
 
-  LIBC_INLINE static constexpr StorageType zero(Sign sign = Sign::POS) {
+  LIBC_INLINE static constexpr FPRep zero(Sign sign = Sign::POS) {
 return encode(sign, BiasedExponent::BITS_ALL_ZEROES(), 
Significand::ZERO());
   }
-  LIBC_INLINE static constexpr StorageType one(Sign sign = Sign::POS) {
+  LIBC_INLINE static constexpr FPRep one(Sign sign = Sign::POS) {
 return encode(sign, Exponent::ZERO(), Significand::ZERO());
   }
-  LIBC_INLINE static constexpr StorageType
-  min_subnormal(Sign sign = Sign::POS) {
+  LIBC_INLINE static constexpr FPRep min_subnormal(Sign sign = Sign::POS) {
 return encode(sign, BiasedExponent::BITS_ALL_ZEROES(), Significand::LSB());
   }
-  LIBC_INLINE static constexpr StorageType
-  max_subnormal(Sign sign = Sign::POS) {
+  LIBC_INLINE static constexpr FPRep max_subnormal(Sign sign = Sign::POS) {
 return encode(sign, BiasedExponent::BITS_ALL_ZEROES(),
   Significand::BITS_ALL_ONES());
   }
-  LIBC_INLINE static constexpr StorageType min_normal(Sign sign = Sign::POS) {
+  LIBC_INLINE static constexpr FPRep min_normal(Sign sign = Sign::POS) {
 return encode(sign, Exponent::MIN(), Significand::ZERO());
   }
-  LIBC_INLINE static constexpr StorageType max_normal(Sign sign = Sign::POS) {
+  LIBC_INLINE static constexpr FPRep max_normal(Sign sign = Sign::POS) {
 return encode(sign, Exponent::MAX(), Significand::BITS_ALL_ONES());
   }
-  LIBC_INLINE static constexpr StorageType inf(Sign sign = Sign::POS) {
+  LIBC_INLINE static constexpr FPRep inf(Sign sign = Sign::POS) {
 return encode(sign, BiasedExponent::BITS_ALL_ONES(), Significand::ZERO());
   }
-  LIBC_INLINE static constexpr StorageType build_nan(Sign sign = Sign::POS,
- StorageType v = 0) {
+  LIBC_INLINE static constexpr FPRep build_nan(Sign sign = Sign::POS,
+   StorageType v = 0) {
 return encode(sign, BiasedExponent::BITS_ALL_ONES(),
   (v ? Significand(v) : (Significand::MSB() >> 1)));
   }
-  LIBC_INLINE static constexpr StorageType
-  build_quiet_nan(Sign sign = Sign::POS, StorageType v = 0) {
+  LIBC_INLINE static constexpr FPRep build_quiet_nan(Sign sign = Sign::POS,
+ StorageType v = 0) {
 return encode(sign, BiasedExponent::BITS_ALL_ONES(),
   Significand::MSB() | Significand(v));
   }
@@ -507,6 +509,7 @@ struct FPRep : public 
FPRepBase {
   using typename UP::BiasedExponent;
   using typename UP::Significand;
   using UP::encode;
+  using UP::UP;
 
 public:
   // The x86 80 bit float represents the leading digit of the mantissa
@@ -570,38 +573,36 @@ struct FPRep : public 
FPRepBase {
 return get_implicit_bit();
   }
 
-  LIBC_INLINE static constexpr StorageType zero(Sign sign = Sign::POS) {
+  LIBC_INLINE static constexpr FPRep zero(Sign sign = Sign::POS) {
 return encode(sign, BiasedExponent::BITS_ALL_ZEROES(), 
Significand::ZERO());
   }
-  LIBC_INLINE static constexpr StorageType one(Sign sign = Sign::POS) {
+  LIBC_INLINE static constexpr FPRep one(Sign sign = Sign::POS) {
 return encode(sign, Exponent::ZERO(), Significand::MSB());
   }
-  LIBC_INLINE static constexpr StorageType
-  min_subnormal(Sign sign = Sign::POS) {
+  LIBC_INLINE static constexpr FPRep min_subnormal(Sign sign = Sign::POS) {
 return encode(sign, BiasedExponent::BITS_ALL_ZEROES(), Significand::LSB());
   }
-  LIBC_INLINE static constexpr StorageType
-  max_subnormal(Sign sig

[compiler-rt] [libc] [llvm] [clang-tools-extra] [clang] [libc] `FPRep` builders return `FPRep` instead of raw `StorageType` (PR #78588)

2024-01-22 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet closed 
https://github.com/llvm/llvm-project/pull/78588
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e38be70 - [Clang] Clarify __builtin_memcpy_inline documentation

2020-09-11 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2020-09-11T07:20:39Z
New Revision: e38be7091ee3d00430652aaa7b66ba3fc8394916

URL: 
https://github.com/llvm/llvm-project/commit/e38be7091ee3d00430652aaa7b66ba3fc8394916
DIFF: 
https://github.com/llvm/llvm-project/commit/e38be7091ee3d00430652aaa7b66ba3fc8394916.diff

LOG: [Clang] Clarify __builtin_memcpy_inline documentation

This patch updates the documentation about `__builtin_memcpy_inline` and 
reorders the sections so it is more consitent and understandable.

Differential Revision: https://reviews.llvm.org/D87458

Added: 


Modified: 
clang/docs/LanguageExtensions.rst

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 60b3f21b3e50..073d9c86e22f 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2408,20 +2408,6 @@ with ``__has_feature(cxx_constexpr_string_builtins)``.
 Memory builtins
 ---
 
- * ``__builtin_memcpy_inline``
-
-.. code-block:: c
-
-  void __builtin_memcpy_inline(void *dst, const void *src, size_t size);
-
-``__builtin_memcpy_inline(dst, src, size)`` is identical to
-``__builtin_memcpy(dst, src, size)`` except that the generated code is
-guaranteed not to call any external functions. See LLVM IR `llvm.memcpy.inline
-`_ Intrinsic 
-for more information.
-
-Note that the `size` argument must be a compile time constant.
-
 Clang provides constant expression evaluation support for builtin forms of the
 following functions from the C standard library headers
  and :
@@ -2439,7 +2425,27 @@ are pointers to arrays with the same trivially copyable 
element type, and the
 given size is an exact multiple of the element size that is no greater than
 the number of elements accessible through the source and destination operands.
 
-Constant evaluation support is not yet provided for 
``__builtin_memcpy_inline``.
+Guaranteed inlined copy
+^^^
+
+.. code-block:: c
+
+  void __builtin_memcpy_inline(void *dst, const void *src, size_t size);
+
+
+``__builtin_memcpy_inline`` has been designed as a building block for efficient
+``memcpy`` implementations. It is identical to ``__builtin_memcpy`` but also
+guarantees not to call any external functions. See LLVM IR `llvm.memcpy.inline
+`_ Intrinsic 
+for more information.
+
+This is useful to implement a custom version of ``memcpy``, implemement a
+``libc`` memcpy or work around the absence of a ``libc``.
+
+Note that the `size` argument must be a compile time constant.
+
+Note that this intrinsic cannot yet be called in a ``constexpr`` context.
+
 
 Atomic Min/Max builtins with memory ordering
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 05d02e5 - Fix invalid link format in Clang LanguageExtension

2020-09-10 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2020-09-10T12:27:50Z
New Revision: 05d02e5a4e54a04f050b52ee30d1860073bd8b34

URL: 
https://github.com/llvm/llvm-project/commit/05d02e5a4e54a04f050b52ee30d1860073bd8b34
DIFF: 
https://github.com/llvm/llvm-project/commit/05d02e5a4e54a04f050b52ee30d1860073bd8b34.diff

LOG: Fix invalid link format in Clang LanguageExtension

Added: 


Modified: 
clang/docs/LanguageExtensions.rst

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index c89f924c58ba..60b3f21b3e50 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2416,9 +2416,9 @@ Memory builtins
 
 ``__builtin_memcpy_inline(dst, src, size)`` is identical to
 ``__builtin_memcpy(dst, src, size)`` except that the generated code is
-guaranteed not to call any external functions. See [LLVM IR 
‘llvm.memcpy.inline’
-Intrinsic](https://llvm.org/docs/LangRef.html#llvm-memcpy-inline-intrinsic) for
-more information.
+guaranteed not to call any external functions. See LLVM IR `llvm.memcpy.inline
+`_ Intrinsic 
+for more information.
 
 Note that the `size` argument must be a compile time constant.
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 89c41c3 - [clang-tidy] Allow disabling integer narrowing conversions for cppcoreguidelines-narrowing-conversions

2021-06-10 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2021-06-10T12:41:57Z
New Revision: 89c41c335dac288d991d1e99ad19493bc89439e4

URL: 
https://github.com/llvm/llvm-project/commit/89c41c335dac288d991d1e99ad19493bc89439e4
DIFF: 
https://github.com/llvm/llvm-project/commit/89c41c335dac288d991d1e99ad19493bc89439e4.diff

LOG: [clang-tidy] Allow disabling integer narrowing conversions for 
cppcoreguidelines-narrowing-conversions

Differential Revision: https://reviews.llvm.org/D104018

Added: 

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-narrowing-conversions-narrowinginteger-option.cpp

Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.h

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-narrowing-conversions.rst

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
index 8ce9afc8f926e..41eabb4f5bf92 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
@@ -35,6 +35,8 @@ auto hasAnyListedName(const std::string &Names) {
 NarrowingConversionsCheck::NarrowingConversionsCheck(StringRef Name,
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
+  WarnOnIntegerNarrowingConversion(
+  Options.get("WarnOnIntegerNarrowingConversion", true)),
   WarnOnFloatingPointNarrowingConversion(
   Options.get("WarnOnFloatingPointNarrowingConversion", true)),
   WarnWithinTemplateInstantiation(
@@ -45,6 +47,8 @@ 
NarrowingConversionsCheck::NarrowingConversionsCheck(StringRef Name,
 
 void NarrowingConversionsCheck::storeOptions(
 ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "WarnOnIntegerNarrowingConversion",
+WarnOnIntegerNarrowingConversion);
   Options.store(Opts, "WarnOnFloatingPointNarrowingConversion",
 WarnOnFloatingPointNarrowingConversion);
   Options.store(Opts, "WarnWithinTemplateInstantiation",
@@ -294,34 +298,37 @@ void NarrowingConversionsCheck::handleIntegralCast(const 
ASTContext &Context,
SourceLocation SourceLoc,
const Expr &Lhs,
const Expr &Rhs) {
-  const BuiltinType *ToType = getBuiltinType(Lhs);
-  // From [conv.integral]p7.3.8:
-  // Conversions to unsigned integer is well defined so no warning is issued.
-  // "The resulting value is the smallest unsigned value equal to the source
-  // value modulo 2^n where n is the number of bits used to represent the
-  // destination type."
-  if (ToType->isUnsignedInteger())
-return;
-  const BuiltinType *FromType = getBuiltinType(Rhs);
-
-  // With this option, we don't warn on conversions that have equivalent width
-  // in bits. eg. uint32 <-> int32.
-  if (!WarnOnEquivalentBitWidth) {
-uint64_t FromTypeSize = Context.getTypeSize(FromType);
-uint64_t ToTypeSize = Context.getTypeSize(ToType);
-if (FromTypeSize == ToTypeSize)
+  if (WarnOnIntegerNarrowingConversion) {
+const BuiltinType *ToType = getBuiltinType(Lhs);
+// From [conv.integral]p7.3.8:
+// Conversions to unsigned integer is well defined so no warning is issued.
+// "The resulting value is the smallest unsigned value equal to the source
+// value modulo 2^n where n is the number of bits used to represent the
+// destination type."
+if (ToType->isUnsignedInteger())
   return;
-  }
+const BuiltinType *FromType = getBuiltinType(Rhs);
 
-  llvm::APSInt IntegerConstant;
-  if (getIntegerConstantExprValue(Context, Rhs, IntegerConstant)) {
-if (!isWideEnoughToHold(Context, IntegerConstant, *ToType))
-  diagNarrowIntegerConstantToSignedInt(SourceLoc, Lhs, Rhs, 
IntegerConstant,
-   Context.getTypeSize(FromType));
-return;
+// With this option, we don't warn on conversions that have equivalent 
width
+// in bits. eg. uint32 <-> int32.
+if (!WarnOnEquivalentBitWidth) {
+  uint64_t FromTypeSize = Context.getTypeSize(FromType);
+  uint64_t ToTypeSize = Context.getTypeSize(ToType);
+  if (FromTypeSize == ToTypeSize)
+return;
+}
+
+llvm::APSInt IntegerConstant;
+if (getIntegerConstantExprValue(Context, Rhs, IntegerConstant)) {
+  if (!isWideEnoughToHold(Context, IntegerConstant, *ToType))
+diagNarrowIntegerConstantToSignedInt(SourceLoc, Lhs, Rhs,
+ IntegerConstant,
+ Context.getTypeSize(FromType));
+  return;
+ 

[clang] 6916ebd - [clang][NFC] Use the TypeSize::getXXXValue() instead of TypeSize::getXXXSize)

2023-01-11 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2023-01-11T16:07:48Z
New Revision: 6916ebd026500061462917666a0e0d228ed52681

URL: 
https://github.com/llvm/llvm-project/commit/6916ebd026500061462917666a0e0d228ed52681
DIFF: 
https://github.com/llvm/llvm-project/commit/6916ebd026500061462917666a0e0d228ed52681.diff

LOG: [clang][NFC] Use the TypeSize::getXXXValue() instead of 
TypeSize::getXXXSize)

This change is one of a series to implement the discussion from
https://reviews.llvm.org/D141134.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGGPUBuiltin.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/TargetInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a6994688d44e1..430b5f43cdd5a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -6784,8 +6784,8 @@ static Value *EmitCommonNeonSISDBuiltinExpr(
 
   Value *Result = CGF.EmitNeonCall(F, Ops, s);
   llvm::Type *ResultType = CGF.ConvertType(E->getType());
-  if (ResultType->getPrimitiveSizeInBits().getFixedSize() <
-  Result->getType()->getPrimitiveSizeInBits().getFixedSize())
+  if (ResultType->getPrimitiveSizeInBits().getFixedValue() <
+  Result->getType()->getPrimitiveSizeInBits().getFixedValue())
 return CGF.Builder.CreateExtractElement(Result, C0);
 
   return CGF.Builder.CreateBitCast(Result, ResultType, s);

diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 06976ba5fb44a..41084956e1979 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1261,7 +1261,7 @@ static llvm::Value *CreateCoercedLoad(Address Src, 
llvm::Type *Ty,
 
   if (llvm::StructType *SrcSTy = dyn_cast(SrcTy)) {
 Src = EnterStructPointerForCoercedAccess(Src, SrcSTy,
- DstSize.getFixedSize(), CGF);
+ DstSize.getFixedValue(), CGF);
 SrcTy = Src.getElementType();
   }
 
@@ -1277,7 +1277,7 @@ static llvm::Value *CreateCoercedLoad(Address Src, 
llvm::Type *Ty,
 
   // If load is legal, just bitcast the src pointer.
   if (!SrcSize.isScalable() && !DstSize.isScalable() &&
-  SrcSize.getFixedSize() >= DstSize.getFixedSize()) {
+  SrcSize.getFixedValue() >= DstSize.getFixedValue()) {
 // Generally SrcSize is never greater than DstSize, since this means we are
 // losing bits. However, this can happen in cases where the structure has
 // additional padding, for example due to a user specified alignment.
@@ -1323,7 +1323,7 @@ static llvm::Value *CreateCoercedLoad(Address Src, 
llvm::Type *Ty,
   CGF.Builder.CreateMemCpy(
   Tmp.getPointer(), Tmp.getAlignment().getAsAlign(), Src.getPointer(),
   Src.getAlignment().getAsAlign(),
-  llvm::ConstantInt::get(CGF.IntPtrTy, SrcSize.getKnownMinSize()));
+  llvm::ConstantInt::get(CGF.IntPtrTy, SrcSize.getKnownMinValue()));
   return CGF.Builder.CreateLoad(Tmp);
 }
 
@@ -1366,7 +1366,7 @@ static void CreateCoercedStore(llvm::Value *Src,
 
   if (llvm::StructType *DstSTy = dyn_cast(DstTy)) {
 Dst = EnterStructPointerForCoercedAccess(Dst, DstSTy,
- SrcSize.getFixedSize(), CGF);
+ SrcSize.getFixedValue(), CGF);
 DstTy = Dst.getElementType();
   }
 
@@ -1393,7 +1393,7 @@ static void CreateCoercedStore(llvm::Value *Src,
   // If store is legal, just bitcast the src pointer.
   if (isa(SrcTy) ||
   isa(DstTy) ||
-  SrcSize.getFixedSize() <= DstSize.getFixedSize()) {
+  SrcSize.getFixedValue() <= DstSize.getFixedValue()) {
 Dst = CGF.Builder.CreateElementBitCast(Dst, SrcTy);
 CGF.EmitAggregateStore(Src, Dst, DstIsVolatile);
   } else {
@@ -1411,7 +1411,7 @@ static void CreateCoercedStore(llvm::Value *Src,
 CGF.Builder.CreateMemCpy(
 Dst.getPointer(), Dst.getAlignment().getAsAlign(), Tmp.getPointer(),
 Tmp.getAlignment().getAsAlign(),
-llvm::ConstantInt::get(CGF.IntPtrTy, DstSize.getFixedSize()));
+llvm::ConstantInt::get(CGF.IntPtrTy, DstSize.getFixedValue()));
   }
 }
 
@@ -4725,7 +4725,7 @@ class AllocAlignAttrEmitter final
 
 static unsigned getMaxVectorWidth(const llvm::Type *Ty) {
   if (auto *VT = dyn_cast(Ty))
-return VT->getPrimitiveSizeInBits().getKnownMinSize();
+return VT->getPrimitiveSizeInBits().getKnownMinValue();
   if (auto *AT = dyn_cast(Ty))
 return getMaxVectorWidth(AT->getElementType());
 

diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index afdee52aec629..6d5e729b1eea9 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3089,7 +3089,7 @@ llvm::Value *CodeGenFunction::EmitCheckValue(llvm::Value 
*V) {
   // Floating-poi

[clang] eaa1f46 - [clang][NFC] Remove dependency on DataLayout::getPrefTypeAlignment

2023-01-13 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2023-01-13T13:19:19Z
New Revision: eaa1f46f11f523104be54de058e812c9d7059819

URL: 
https://github.com/llvm/llvm-project/commit/eaa1f46f11f523104be54de058e812c9d7059819
DIFF: 
https://github.com/llvm/llvm-project/commit/eaa1f46f11f523104be54de058e812c9d7059819.diff

LOG: [clang][NFC] Remove dependency on DataLayout::getPrefTypeAlignment

Added: 


Modified: 
clang/include/clang/AST/CharUnits.h
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CodeGenFunction.h

Removed: 




diff  --git a/clang/include/clang/AST/CharUnits.h 
b/clang/include/clang/AST/CharUnits.h
index cd3dab00c69f8..ee0d402fc74af 100644
--- a/clang/include/clang/AST/CharUnits.h
+++ b/clang/include/clang/AST/CharUnits.h
@@ -64,6 +64,12 @@ namespace clang {
 return CharUnits(Quantity);
   }
 
+  /// fromAlign - Construct a CharUnits quantity from an llvm::Align
+  /// quantity.
+  static CharUnits fromAlign(llvm::Align Quantity) {
+return CharUnits(Quantity.value());
+  }
+
   // Compound assignment.
   CharUnits& operator+= (const CharUnits &Other) {
 Quantity += Other.Quantity;

diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 41084956e1979..b8de9fb7224e0 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1148,8 +1148,8 @@ static Address 
CreateTempAllocaForCoercion(CodeGenFunction &CGF, llvm::Type *Ty,
CharUnits MinAlign,
const Twine &Name = "tmp") {
   // Don't use an alignment that's worse than what LLVM would prefer.
-  auto PrefAlign = CGF.CGM.getDataLayout().getPrefTypeAlignment(Ty);
-  CharUnits Align = std::max(MinAlign, CharUnits::fromQuantity(PrefAlign));
+  auto PrefAlign = CGF.CGM.getDataLayout().getPrefTypeAlign(Ty);
+  CharUnits Align = std::max(MinAlign, CharUnits::fromAlign(PrefAlign));
 
   return CGF.CreateTempAlloca(Ty, Align, Name + ".coerce");
 }
@@ -5161,15 +5161,14 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
 
 llvm::Type *scalarType = RV.getScalarVal()->getType();
 auto scalarSize = CGM.getDataLayout().getTypeAllocSize(scalarType);
-auto scalarAlign = 
CGM.getDataLayout().getPrefTypeAlignment(scalarType);
+auto scalarAlign = CGM.getDataLayout().getPrefTypeAlign(scalarType);
 
 // Materialize to a temporary.
-addr =
-CreateTempAlloca(RV.getScalarVal()->getType(),
- CharUnits::fromQuantity(std::max(
- layout->getAlignment().value(), scalarAlign)),
- "tmp",
- /*ArraySize=*/nullptr, &AllocaAddr);
+addr = CreateTempAlloca(
+RV.getScalarVal()->getType(),
+CharUnits::fromAlign(std::max(layout->getAlignment(), 
scalarAlign)),
+"tmp",
+/*ArraySize=*/nullptr, &AllocaAddr);
 tempSize = EmitLifetimeStart(scalarSize, AllocaAddr.getPointer());
 
 Builder.CreateStore(RV.getScalarVal(), addr);

diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 34974c63984e6..ad7871d7cc7f5 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -123,7 +123,7 @@ llvm::AllocaInst 
*CodeGenFunction::CreateTempAlloca(llvm::Type *Ty,
 Address CodeGenFunction::CreateDefaultAlignTempAlloca(llvm::Type *Ty,
   const Twine &Name) {
   CharUnits Align =
-  CharUnits::fromQuantity(CGM.getDataLayout().getPrefTypeAlignment(Ty));
+  CharUnits::fromAlign(CGM.getDataLayout().getPrefTypeAlign(Ty));
   return CreateTempAlloca(Ty, Align, Name);
 }
 

diff  --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index f1d7cc7108a8e..66f60585052a3 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4850,10 +4850,10 @@ DominatingLLVMValue::save(CodeGenFunction &CGF, 
llvm::Value *value) {
   if (!needsSaving(value)) return saved_type(value, false);
 
   // Otherwise, we need an alloca.
-  auto align = CharUnits::fromQuantity(
-CGF.CGM.getDataLayout().getPrefTypeAlignment(value->getType()));
+  auto align = CharUnits::fromAlign(
+  CGF.CGM.getDataLayout().getPrefTypeAlign(value->getType()));
   Address alloca =
-CGF.CreateTempAlloca(value->getType(), align, "cond-cleanup.save");
+  CGF.CreateTempAlloca(value->getType(), align, "cond-cleanup.save");
   CGF.Builder.CreateStore(value, alloca);
 
   return saved_type(alloca.getPointer(), true);



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] bf5c17e - [clang][NFC] Remove dependency on DataLayout::getPrefTypeAlignment

2023-01-13 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2023-01-13T15:01:29Z
New Revision: bf5c17ed0f402f603782d28264dab1157994c43d

URL: 
https://github.com/llvm/llvm-project/commit/bf5c17ed0f402f603782d28264dab1157994c43d
DIFF: 
https://github.com/llvm/llvm-project/commit/bf5c17ed0f402f603782d28264dab1157994c43d.diff

LOG: [clang][NFC] Remove dependency on DataLayout::getPrefTypeAlignment

Added: 


Modified: 
clang/include/clang/AST/CharUnits.h
clang/lib/CodeGen/CGBlocks.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprConstant.cpp
clang/lib/CodeGen/CGObjCMac.cpp
clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
clang/lib/CodeGen/CGVTT.cpp
clang/lib/CodeGen/CGVTables.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/CodeGen/ConstantInitBuilder.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/lib/CodeGen/SwiftCallingConv.cpp
clang/lib/CodeGen/TargetInfo.cpp

Removed: 




diff  --git a/clang/include/clang/AST/CharUnits.h 
b/clang/include/clang/AST/CharUnits.h
index ee0d402fc74a..c06354451dfb 100644
--- a/clang/include/clang/AST/CharUnits.h
+++ b/clang/include/clang/AST/CharUnits.h
@@ -64,9 +64,9 @@ namespace clang {
 return CharUnits(Quantity);
   }
 
-  /// fromAlign - Construct a CharUnits quantity from an llvm::Align
+  /// fromQuantity - Construct a CharUnits quantity from an llvm::Align
   /// quantity.
-  static CharUnits fromAlign(llvm::Align Quantity) {
+  static CharUnits fromQuantity(llvm::Align Quantity) {
 return CharUnits(Quantity.value());
   }
 

diff  --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 1a4be440c53d..6e4a0dbf2335 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -522,7 +522,7 @@ static void initializeForBlockHeader(CodeGenModule &CGM, 
CGBlockInfo &info,
   for (auto *I : Helper->getCustomFieldTypes()) /* custom fields */ {
 // TargetOpenCLBlockHelp needs to make sure the struct is packed.
 // If necessary, add padding fields to the custom fields.
-unsigned Align = CGM.getDataLayout().getABITypeAlignment(I);
+unsigned Align = CGM.getDataLayout().getABITypeAlign(I).value();
 if (BlockAlign < Align)
   BlockAlign = Align;
 assert(Offset % Align == 0);
@@ -2672,7 +2672,7 @@ const BlockByrefInfo 
&CodeGenFunction::getBlockByrefInfo(const VarDecl *D) {
 size = varOffset;
 
   // Conversely, we might have to prevent LLVM from inserting padding.
-  } else if (CGM.getDataLayout().getABITypeAlignment(varTy) >
+  } else if (CGM.getDataLayout().getABITypeAlign(varTy) >
  uint64_t(varAlign.getQuantity())) {
 packed = true;
   }

diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index b8de9fb7224e..276d91fa2758 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1149,7 +1149,7 @@ static Address 
CreateTempAllocaForCoercion(CodeGenFunction &CGF, llvm::Type *Ty,
const Twine &Name = "tmp") {
   // Don't use an alignment that's worse than what LLVM would prefer.
   auto PrefAlign = CGF.CGM.getDataLayout().getPrefTypeAlign(Ty);
-  CharUnits Align = std::max(MinAlign, CharUnits::fromAlign(PrefAlign));
+  CharUnits Align = std::max(MinAlign, CharUnits::fromQuantity(PrefAlign));
 
   return CGF.CreateTempAlloca(Ty, Align, Name + ".coerce");
 }
@@ -5166,7 +5166,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
 // Materialize to a temporary.
 addr = CreateTempAlloca(
 RV.getScalarVal()->getType(),
-CharUnits::fromAlign(std::max(layout->getAlignment(), 
scalarAlign)),
+CharUnits::fromQuantity(std::max(layout->getAlignment(), 
scalarAlign)),
 "tmp",
 /*ArraySize=*/nullptr, &AllocaAddr);
 tempSize = EmitLifetimeStart(scalarSize, AllocaAddr.getPointer());

diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index ad7871d7cc7f..ca665dbe7d0a 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -123,7 +123,7 @@ llvm::AllocaInst 
*CodeGenFunction::CreateTempAlloca(llvm::Type *Ty,
 Address CodeGenFunction::CreateDefaultAlignTempAlloca(llvm::Type *Ty,
   const Twine &Name) {
   CharUnits Align =
-  CharUnits::fromAlign(CGM.getDataLayout().getPrefTypeAlign(Ty));
+  CharUnits::fromQuantity(CGM.getDataLayout().getPrefTypeAlign(Ty));
   return CreateTempAlloca(Ty, Align, Name);
 }
 

diff  --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index 7dc105215e7d..8e74f0295301 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++

[clang] d9b8d13 - [NFC][Alignment] Use MaybeAlign in CGCleanup/CGExpr

2022-06-14 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2022-06-14T10:56:36Z
New Revision: d9b8d13f8b58086e2c8d5c59be6f79222a07931e

URL: 
https://github.com/llvm/llvm-project/commit/d9b8d13f8b58086e2c8d5c59be6f79222a07931e
DIFF: 
https://github.com/llvm/llvm-project/commit/d9b8d13f8b58086e2c8d5c59be6f79222a07931e.diff

LOG: [NFC][Alignment] Use MaybeAlign in CGCleanup/CGExpr

Added: 


Modified: 
clang/include/clang/AST/CharUnits.h
clang/lib/CodeGen/CGCleanup.cpp
clang/lib/CodeGen/CGExpr.cpp

Removed: 




diff  --git a/clang/include/clang/AST/CharUnits.h 
b/clang/include/clang/AST/CharUnits.h
index f14d3abf71e5e..2705f24789e4c 100644
--- a/clang/include/clang/AST/CharUnits.h
+++ b/clang/include/clang/AST/CharUnits.h
@@ -182,6 +182,12 @@ namespace clang {
   /// Beware llvm::Align assumes power of two 8-bit bytes.
   llvm::Align getAsAlign() const { return llvm::Align(Quantity); }
 
+  /// getAsMaybeAlign - Returns Quantity as a valid llvm::Align or
+  /// llvm::None, Beware llvm::MaybeAlign assumes power of two 8-bit bytes.
+  llvm::MaybeAlign getAsMaybeAlign() const {
+return llvm::MaybeAlign(Quantity);
+  }
+
   /// alignTo - Returns the next integer (mod 2**64) that is
   /// greater than or equal to this quantity and is a multiple of \p Align.
   /// Align must be non-zero.

diff  --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index a10851edfb82c..5035ed34358d2 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -77,7 +77,7 @@ RValue 
DominatingValue::saved_type::restore(CodeGenFunction &CGF) {
   auto getSavingAddress = [&](llvm::Value *value) {
 auto *AI = cast(value);
 return Address(value, AI->getAllocatedType(),
-   CharUnits::fromQuantity(AI->getAlignment()));
+   CharUnits::fromQuantity(AI->getAlign().value()));
   };
   switch (K) {
   case ScalarLiteral:

diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 3d7f13aed0aba..cbeb6c938bee7 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -757,23 +757,23 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, 
SourceLocation Loc,
 }
   }
 
-  uint64_t AlignVal = 0;
+  llvm::MaybeAlign AlignVal;
   llvm::Value *PtrAsInt = nullptr;
 
   if (SanOpts.has(SanitizerKind::Alignment) &&
   !SkippedChecks.has(SanitizerKind::Alignment)) {
-AlignVal = Alignment.getQuantity();
+AlignVal = Alignment.getAsMaybeAlign();
 if (!Ty->isIncompleteType() && !AlignVal)
   AlignVal = CGM.getNaturalTypeAlignment(Ty, nullptr, nullptr,
  /*ForPointeeType=*/true)
- .getQuantity();
+ .getAsMaybeAlign();
 
 // The glvalue must be suitably aligned.
-if (AlignVal > 1 &&
-(!PtrToAlloca || PtrToAlloca->getAlignment() < AlignVal)) {
+if (AlignVal && *AlignVal > llvm::Align(1) &&
+(!PtrToAlloca || PtrToAlloca->getAlign() < *AlignVal)) {
   PtrAsInt = Builder.CreatePtrToInt(Ptr, IntPtrTy);
   llvm::Value *Align = Builder.CreateAnd(
-  PtrAsInt, llvm::ConstantInt::get(IntPtrTy, AlignVal - 1));
+  PtrAsInt, llvm::ConstantInt::get(IntPtrTy, AlignVal->value() - 1));
   llvm::Value *Aligned =
   Builder.CreateICmpEQ(Align, llvm::ConstantInt::get(IntPtrTy, 0));
   if (Aligned != True)
@@ -782,12 +782,9 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, 
SourceLocation Loc,
   }
 
   if (Checks.size() > 0) {
-// Make sure we're not losing information. Alignment needs to be a power of
-// 2
-assert(!AlignVal || (uint64_t)1 << llvm::Log2_64(AlignVal) == AlignVal);
 llvm::Constant *StaticData[] = {
 EmitCheckSourceLocation(Loc), EmitCheckTypeDescriptor(Ty),
-llvm::ConstantInt::get(Int8Ty, AlignVal ? llvm::Log2_64(AlignVal) : 1),
+llvm::ConstantInt::get(Int8Ty, AlignVal ? llvm::Log2(*AlignVal) : 1),
 llvm::ConstantInt::get(Int8Ty, TCK)};
 EmitCheck(Checks, SanitizerHandler::TypeMismatch, StaticData,
   PtrAsInt ? PtrAsInt : Ptr);



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c698189 - [NFC] Format CGBuilder.h

2022-06-03 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2022-06-03T07:54:01Z
New Revision: c698189696d33e7304d94cd4212bd81818ea81a0

URL: 
https://github.com/llvm/llvm-project/commit/c698189696d33e7304d94cd4212bd81818ea81a0
DIFF: 
https://github.com/llvm/llvm-project/commit/c698189696d33e7304d94cd4212bd81818ea81a0.diff

LOG: [NFC] Format CGBuilder.h

Added: 


Modified: 
clang/lib/CodeGen/CGBuilder.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h
index c087aa463588..68618df60155 100644
--- a/clang/lib/CodeGen/CGBuilder.h
+++ b/clang/lib/CodeGen/CGBuilder.h
@@ -32,6 +32,7 @@ class CGBuilderInserter final : public 
llvm::IRBuilderDefaultInserter {
   void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name,
 llvm::BasicBlock *BB,
 llvm::BasicBlock::iterator InsertPt) const override;
+
 private:
   CodeGenFunction *CGF = nullptr;
 };
@@ -45,17 +46,18 @@ class CGBuilderTy : public CGBuilderBaseTy {
   /// Storing a reference to the type cache here makes it a lot easier
   /// to build natural-feeling, target-specific IR.
   const CodeGenTypeCache &TypeCache;
+
 public:
   CGBuilderTy(const CodeGenTypeCache &TypeCache, llvm::LLVMContext &C)
-: CGBuilderBaseTy(C), TypeCache(TypeCache) {}
-  CGBuilderTy(const CodeGenTypeCache &TypeCache,
-  llvm::LLVMContext &C, const llvm::ConstantFolder &F,
+  : CGBuilderBaseTy(C), TypeCache(TypeCache) {}
+  CGBuilderTy(const CodeGenTypeCache &TypeCache, llvm::LLVMContext &C,
+  const llvm::ConstantFolder &F,
   const CGBuilderInserterTy &Inserter)
-: CGBuilderBaseTy(C, F, Inserter), TypeCache(TypeCache) {}
+  : CGBuilderBaseTy(C, F, Inserter), TypeCache(TypeCache) {}
   CGBuilderTy(const CodeGenTypeCache &TypeCache, llvm::Instruction *I)
-: CGBuilderBaseTy(I), TypeCache(TypeCache) {}
+  : CGBuilderBaseTy(I), TypeCache(TypeCache) {}
   CGBuilderTy(const CodeGenTypeCache &TypeCache, llvm::BasicBlock *BB)
-: CGBuilderBaseTy(BB), TypeCache(TypeCache) {}
+  : CGBuilderBaseTy(BB), TypeCache(TypeCache) {}
 
   llvm::ConstantInt *getSize(CharUnits N) {
 return llvm::ConstantInt::get(TypeCache.SizeTy, N.getQuantity());
@@ -102,7 +104,8 @@ class CGBuilderTy : public CGBuilderBaseTy {
 
   using CGBuilderBaseTy::CreateAlignedStore;
   llvm::StoreInst *CreateAlignedStore(llvm::Value *Val, llvm::Value *Addr,
-  CharUnits Align, bool IsVolatile = 
false) {
+  CharUnits Align,
+  bool IsVolatile = false) {
 return CreateAlignedStore(Val, Addr, Align.getAsAlign(), IsVolatile);
   }
 
@@ -165,8 +168,8 @@ class CGBuilderTy : public CGBuilderBaseTy {
   Address CreateElementBitCast(Address Addr, llvm::Type *Ty,
const llvm::Twine &Name = "") {
 auto *PtrTy = Ty->getPointerTo(Addr.getAddressSpace());
-return Address(CreateBitCast(Addr.getPointer(), PtrTy, Name),
-   Ty, Addr.getAlignment());
+return Address(CreateBitCast(Addr.getPointer(), PtrTy, Name), Ty,
+   Addr.getAlignment());
   }
 
   using CGBuilderBaseTy::CreatePointerBitCastOrAddrSpaceCast;
@@ -193,10 +196,10 @@ class CGBuilderTy : public CGBuilderBaseTy {
 const llvm::StructLayout *Layout = DL.getStructLayout(ElTy);
 auto Offset = CharUnits::fromQuantity(Layout->getElementOffset(Index));
 
-return Address(CreateStructGEP(Addr.getElementType(),
-   Addr.getPointer(), Index, Name),
-   ElTy->getElementType(Index),
-   Addr.getAlignment().alignmentAtOffset(Offset));
+return Address(
+CreateStructGEP(Addr.getElementType(), Addr.getPointer(), Index, Name),
+ElTy->getElementType(Index),
+Addr.getAlignment().alignmentAtOffset(Offset));
   }
 
   /// Given
@@ -264,10 +267,10 @@ class CGBuilderTy : public CGBuilderBaseTy {
 CharUnits EltSize =
 CharUnits::fromQuantity(DL.getTypeAllocSize(Addr.getElementType()));
 
-return Address(CreateGEP(Addr.getElementType(), Addr.getPointer(), Index,
- Name),
-   Addr.getElementType(),
-   Addr.getAlignment().alignmentOfArrayElement(EltSize));
+return Address(
+CreateGEP(Addr.getElementType(), Addr.getPointer(), Index, Name),
+Addr.getElementType(),
+Addr.getAlignment().alignmentOfArrayElement(EltSize));
   }
 
   /// Given a pointer to i8, adjust it by a given constant offset.
@@ -342,8 +345,7 @@ class CGBuilderTy : public CGBuilderBaseTy {
   }
 
   using CGBuilderBaseTy::CreatePreserveStructAccessIndex;
-  Address CreatePreserveStructAccessIndex(Address Addr,
-  unsigned Index,
+  Address CreatePreserveStructAccessIndex(Address Addr, unsigned Index

[clang] d8b540c - Cleanup sema checking for buitlin_memcpy_inline

2022-06-07 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2022-06-07T09:49:36Z
New Revision: d8b540cd312cf924b1904047b56cf8a1cea333f9

URL: 
https://github.com/llvm/llvm-project/commit/d8b540cd312cf924b1904047b56cf8a1cea333f9
DIFF: 
https://github.com/llvm/llvm-project/commit/d8b540cd312cf924b1904047b56cf8a1cea333f9.diff

LOG: Cleanup sema checking for buitlin_memcpy_inline

Added: 


Modified: 
clang/include/clang/Basic/Builtins.def
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/builtins-memcpy-inline.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index f47e8de806e21..173431ce39884 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -555,7 +555,7 @@ BUILTIN(__builtin_malloc, "v*z", "nF")
 BUILTIN(__builtin_memchr, "v*vC*iz", "nF")
 BUILTIN(__builtin_memcmp, "ivC*vC*z", "nF")
 BUILTIN(__builtin_memcpy, "v*v*vC*z", "nF")
-BUILTIN(__builtin_memcpy_inline, "vv*vC*Iz", "nt")
+BUILTIN(__builtin_memcpy_inline, "vv*vC*Iz", "n")
 BUILTIN(__builtin_memmove, "v*v*vC*z", "nF")
 BUILTIN(__builtin_mempcpy, "v*v*vC*z", "nF")
 BUILTIN(__builtin_memset, "v*v*iz", "nF")

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 453364c3ac3d9..657238eabd9dc 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2265,19 +2265,6 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
   case Builtin::BI__builtin_nontemporal_store:
 return SemaBuiltinNontemporalOverloaded(TheCallResult);
   case Builtin::BI__builtin_memcpy_inline: {
-if (checkArgCount(*this, TheCall, 3))
-  return ExprError();
-auto ArgArrayConversionFailed = [&](unsigned Arg) {
-  ExprResult ArgExpr =
-  DefaultFunctionArrayLvalueConversion(TheCall->getArg(Arg));
-  if (ArgExpr.isInvalid())
-return true;
-  TheCall->setArg(Arg, ArgExpr.get());
-  return false;
-};
-
-if (ArgArrayConversionFailed(0) || ArgArrayConversionFailed(1))
-  return true;
 clang::Expr *SizeOp = TheCall->getArg(2);
 // We warn about copying to or from `nullptr` pointers when `size` is
 // greater than 0. When `size` is value dependent we cannot evaluate its

diff  --git a/clang/test/Sema/builtins-memcpy-inline.cpp 
b/clang/test/Sema/builtins-memcpy-inline.cpp
index ab0a8700a6c98..9d905a9335c4e 100644
--- a/clang/test/Sema/builtins-memcpy-inline.cpp
+++ b/clang/test/Sema/builtins-memcpy-inline.cpp
@@ -7,6 +7,10 @@
 // expected-warning@-1 {{defined as expected}}
 #endif
 
+void test_memcpy_inline_invalid_arg_types() {
+  __builtin_memcpy_inline(1, 2, 3); // expected-error {{cannot initialize a 
parameter of type 'void *' with an rvalue of type 'int'}}
+}
+
 void test_memcpy_inline_null_src(void *ptr) {
   __builtin_memcpy_inline(ptr, NULL, 4); // expected-warning {{null passed to 
a callee that requires a non-null argument}}
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 19647e5 - Fix change of variable name in test

2022-06-07 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2022-06-07T11:20:57Z
New Revision: 19647e5b3b77b1c2089756e99abf88205d534ba4

URL: 
https://github.com/llvm/llvm-project/commit/19647e5b3b77b1c2089756e99abf88205d534ba4
DIFF: 
https://github.com/llvm/llvm-project/commit/19647e5b3b77b1c2089756e99abf88205d534ba4.diff

LOG: Fix change of variable name in test

Added: 


Modified: 
clang/test/CodeGen/builtins-memcpy-inline.c

Removed: 




diff  --git a/clang/test/CodeGen/builtins-memcpy-inline.c 
b/clang/test/CodeGen/builtins-memcpy-inline.c
index d4eb8c62ff2f..c9ea43ed9622 100644
--- a/clang/test/CodeGen/builtins-memcpy-inline.c
+++ b/clang/test/CodeGen/builtins-memcpy-inline.c
@@ -21,6 +21,6 @@ void test_memcpy_inline_4(void *dst, const void *src) {
 
 // CHECK-LABEL: define{{.*}} void @test_memcpy_inline_aligned_buffers(i64* 
noundef %dst, i64* noundef %src)
 void test_memcpy_inline_aligned_buffers(unsigned long long *dst, const 
unsigned long long *src) {
-  // CHECK:   call void @llvm.memcpy.inline.p0i8.p0i8.i64(i8* align 8 %2, i8* 
align 8 %3, i64 4, i1 false)
+  // CHECK:   call void @llvm.memcpy.inline.p0i8.p0i8.i64(i8* align 8 %1, i8* 
align 8 %3, i64 4, i1 false) 
   __builtin_memcpy_inline(dst, src, 4);
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 38637ee - [clang] Add support for __builtin_memset_inline

2022-06-10 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2022-06-10T13:13:59Z
New Revision: 38637ee477541370a90b37f149069d8e5c0c2efd

URL: 
https://github.com/llvm/llvm-project/commit/38637ee477541370a90b37f149069d8e5c0c2efd
DIFF: 
https://github.com/llvm/llvm-project/commit/38637ee477541370a90b37f149069d8e5c0c2efd.diff

LOG: [clang] Add support for __builtin_memset_inline

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.

Differential Revision: https://reviews.llvm.org/D126903

Added: 
clang/test/CodeGen/builtins-memset-inline.c
clang/test/Sema/builtins-memset-inline.cpp
llvm/test/CodeGen/AArch64/memset-inline.ll
llvm/test/CodeGen/AArch64/memset-vs-memset-inline.ll
llvm/test/CodeGen/X86/memset-inline.ll
llvm/test/CodeGen/X86/memset-vs-memset-inline.ll
llvm/test/Verifier/memset-inline.ll

Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/Builtins.def
clang/lib/CodeGen/CGBuilder.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Sema/SemaChecking.cpp
llvm/docs/LangRef.rst
llvm/include/llvm/CodeGen/SelectionDAG.h
llvm/include/llvm/CodeGen/SelectionDAGTargetInfo.h
llvm/include/llvm/CodeGen/TargetLowering.h
llvm/include/llvm/IR/IRBuilder.h
llvm/include/llvm/IR/IntrinsicInst.h
llvm/include/llvm/IR/Intrinsics.td
llvm/lib/Analysis/Lint.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/lib/IR/IRBuilder.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Target/AArch64/AArch64SelectionDAGInfo.cpp
llvm/lib/Target/AArch64/AArch64SelectionDAGInfo.h
llvm/lib/Target/ARM/ARMSelectionDAGInfo.cpp
llvm/lib/Target/ARM/ARMSelectionDAGInfo.h
llvm/lib/Target/SystemZ/SystemZISelLowering.cpp
llvm/lib/Target/SystemZ/SystemZSelectionDAGInfo.cpp
llvm/lib/Target/SystemZ/SystemZSelectionDAGInfo.h
llvm/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp
llvm/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.h
llvm/lib/Target/X86/X86SelectionDAGInfo.cpp
llvm/lib/Target/X86/X86SelectionDAGInfo.h
llvm/test/Other/lint.ll
llvm/test/Verifier/intrinsic-immarg.ll

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 44848a20dca3..3e4108bdbe50 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3218,6 +3218,26 @@ Note that the `size` argument must be a compile time 
constant.
 
 Note that this intrinsic cannot yet be called in a ``constexpr`` context.
 
+Guaranteed inlined memset
+^
+
+. code-block:: c
+
+  void __builtin_memset_inline(void *dst, int value, size_t size);
+
+
+``__builtin_memset_inline`` has been designed as a building block for efficient
+``memset`` implementations. It is identical to ``__builtin_memset`` but also
+guarantees not to call any external functions. See LLVM IR `llvm.memset.inline
+`_ intrinsic
+for more information.
+
+This is useful to implement a custom version of ``memset``, implement a
+``libc`` memset or work around the absence of a ``libc``.
+
+Note that the `size` argument must be a compile time constant.
+
+Note that this intrinsic cannot yet be called in a ``constexpr`` context.
 
 Atomic Min/Max builtins with memory ordering
 

diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 173431ce3988..c084cc2c4cbd 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -559,6 +559,7 @@ BUILTIN(__builtin_memcpy_inline, "vv*vC*Iz", "n")
 BUILTIN(__builtin_memmove, "v*v*vC*z", "nF")
 BUILTIN(__builtin_mempcpy, "v*v*vC*z", "nF")
 BUILTIN(__builtin_memset, "v*v*iz", "nF")
+BUILTIN(__builtin_memset_inline, "vv*iIz", "n")
 BUILTIN(__builtin_printf, "icC*.", "Fp:0:")
 BUILTIN(__builtin_stpcpy, "c*c*cC*", "nF")
 BUILTIN(__builtin_stpncpy, "c*c*cC*z", "nF")

diff  --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h
index 68618df60155..2fcfea64ede6 100644
--- a/clang/lib/CodeGen/CGBuilder.h
+++ b/clang/lib/CodeGen/CGBuilder.h
@@ -344,6 +344,14 @@ class CGBuilderTy : public CGBuilderBaseTy {
 Dest.getAlignment().getAsAlign(), IsVolatile);
   }
 
+  using CGBuilderBaseTy::CreateMemSetInline;
+  llvm::CallInst *CreateMemSetInline(Address Dest, llvm::Value *Value,
+   

[clang-tools-extra] [clang-tidy] Update llvmlibc-implementation-in-namespace to new rules (PR #66504)

2023-09-21 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet updated 
https://github.com/llvm/llvm-project/pull/66504

>From f1427a81c4a3425c1a574316fc26d2c74297b34b Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet 
Date: Fri, 15 Sep 2023 12:34:17 +
Subject: [PATCH 1/4] [clang-tidy] Update llvmlibc-implementation-in-namespace
 to new rules

This is the implementation of step 3 of
https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079.
---
 .../ImplementationInNamespaceCheck.cpp| 21 -
 .../llvmlibc/implementation-in-namespace.rst  | 23 +-
 .../llvmlibc/implementation-in-namespace.cpp  | 31 +--
 3 files changed, 50 insertions(+), 25 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp 
b/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
index d05310f09ef773a..69a385f5be9807f 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
@@ -14,7 +14,9 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::llvm_libc {
 
-const static StringRef RequiredNamespace = "__llvm_libc";
+const static StringRef RequiredNamespaceStart = "__llvm_libc";
+const static StringRef RequiredNamespaceMacroName = "LIBC_NAMESPACE";
+
 void ImplementationInNamespaceCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   decl(hasParent(translationUnitDecl()), unless(linkageSpecDecl()))
@@ -29,16 +31,19 @@ void ImplementationInNamespaceCheck::check(
   if (!Result.SourceManager->isInMainFile(MatchedDecl->getLocation()))
 return;
 
-  if (const auto *NS = dyn_cast(MatchedDecl)) {
-if (NS->getName() != RequiredNamespace) {
-  diag(NS->getLocation(), "'%0' needs to be the outermost namespace")
-  << RequiredNamespace;
-}
+  if (auto *NS = dyn_cast(MatchedDecl)) {
+if (!Result.SourceManager->isMacroBodyExpansion(NS->getLocation()))
+  diag(NS->getLocation(),
+   "the outermost namespace should be the '%0' macro")
+  << RequiredNamespaceMacroName;
+else if (!NS->getName().starts_with(RequiredNamespaceStart))
+  diag(NS->getLocation(), "the outermost namespace should start with '%0'")
+  << RequiredNamespaceStart;
 return;
   }
   diag(MatchedDecl->getLocation(),
-   "declaration must be declared within the '%0' namespace")
-  << RequiredNamespace;
+   "declaration must be declared within a namespace starting with '%0'")
+  << RequiredNamespaceStart;
 }
 
 } // namespace clang::tidy::llvm_libc
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
index 33d6dc8ff125c84..47ea2b866a93404 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
@@ -8,21 +8,30 @@ correct namespace.
 
 .. code-block:: c++
 
-// Correct: implementation inside the correct namespace.
-namespace __llvm_libc {
+// Implementation inside the LIBC_NAMESPACE namespace.
+// Correct if:
+// - LIBC_NAMESPACE is a macro
+// - LIBC_NAMESPACE expansion starts with `__llvm_libc`
+namespace LIBC_NAMESPACE {
 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
-// Namespaces within __llvm_libc namespace are allowed.
-namespace inner{
+// Namespaces within LIBC_NAMESPACE namespace are allowed.
+namespace inner {
 int localVar = 0;
 }
 // Functions with C linkage are allowed.
-extern "C" void str_fuzz(){}
+extern "C" void str_fuzz() {}
 }
 
-// Incorrect: implementation not in a namespace.
+// Incorrect: implementation not in the LIBC_NAMESPACE namespace.
 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
 
-// Incorrect: outer most namespace is not correct.
+// Incorrect: outer most namespace is not the LIBC_NAMESPACE macro.
 namespace something_else {
 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
 }
+
+// Incorrect: outer most namespace expansion does not start with 
`__llvm_libc`.
+#define LIBC_NAMESPACE custom_namespace
+namespace LIBC_NAMESPACE {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+}
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
index e75556a623b655c..16c5f9ca1067ec5 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
@@ -3

[clang-tools-extra] [clang-tidy] Update llvmlibc-implementation-in-namespace to new rules (PR #66504)

2023-09-21 Thread Guillaume Chatelet via cfe-commits


@@ -30,15 +32,18 @@ void ImplementationInNamespaceCheck::check(
 return;
 
   if (const auto *NS = dyn_cast(MatchedDecl)) {
-if (NS->getName() != RequiredNamespace) {
-  diag(NS->getLocation(), "'%0' needs to be the outermost namespace")
-  << RequiredNamespace;
-}
+if (!Result.SourceManager->isMacroBodyExpansion(NS->getLocation()))
+  diag(NS->getLocation(),
+   "the outermost namespace should be the '%0' macro")
+  << RequiredNamespaceMacroName;
+else if (!NS->getName().starts_with(RequiredNamespaceStart))
+  diag(NS->getLocation(), "the outermost namespace should start with '%0'")
+  << RequiredNamespaceStart;
 return;
   }
   diag(MatchedDecl->getLocation(),

gchatelet wrote:

This is the case where we are not in any namespace but the message is 
misleading. Thx for pointing this out. I'll fix it shortly.

https://github.com/llvm/llvm-project/pull/66504
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Update llvmlibc-implementation-in-namespace to new rules (PR #66504)

2023-09-21 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet updated 
https://github.com/llvm/llvm-project/pull/66504

>From f1427a81c4a3425c1a574316fc26d2c74297b34b Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet 
Date: Fri, 15 Sep 2023 12:34:17 +
Subject: [PATCH 1/5] [clang-tidy] Update llvmlibc-implementation-in-namespace
 to new rules

This is the implementation of step 3 of
https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079.
---
 .../ImplementationInNamespaceCheck.cpp| 21 -
 .../llvmlibc/implementation-in-namespace.rst  | 23 +-
 .../llvmlibc/implementation-in-namespace.cpp  | 31 +--
 3 files changed, 50 insertions(+), 25 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp 
b/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
index d05310f09ef773a..69a385f5be9807f 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
@@ -14,7 +14,9 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::llvm_libc {
 
-const static StringRef RequiredNamespace = "__llvm_libc";
+const static StringRef RequiredNamespaceStart = "__llvm_libc";
+const static StringRef RequiredNamespaceMacroName = "LIBC_NAMESPACE";
+
 void ImplementationInNamespaceCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   decl(hasParent(translationUnitDecl()), unless(linkageSpecDecl()))
@@ -29,16 +31,19 @@ void ImplementationInNamespaceCheck::check(
   if (!Result.SourceManager->isInMainFile(MatchedDecl->getLocation()))
 return;
 
-  if (const auto *NS = dyn_cast(MatchedDecl)) {
-if (NS->getName() != RequiredNamespace) {
-  diag(NS->getLocation(), "'%0' needs to be the outermost namespace")
-  << RequiredNamespace;
-}
+  if (auto *NS = dyn_cast(MatchedDecl)) {
+if (!Result.SourceManager->isMacroBodyExpansion(NS->getLocation()))
+  diag(NS->getLocation(),
+   "the outermost namespace should be the '%0' macro")
+  << RequiredNamespaceMacroName;
+else if (!NS->getName().starts_with(RequiredNamespaceStart))
+  diag(NS->getLocation(), "the outermost namespace should start with '%0'")
+  << RequiredNamespaceStart;
 return;
   }
   diag(MatchedDecl->getLocation(),
-   "declaration must be declared within the '%0' namespace")
-  << RequiredNamespace;
+   "declaration must be declared within a namespace starting with '%0'")
+  << RequiredNamespaceStart;
 }
 
 } // namespace clang::tidy::llvm_libc
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
index 33d6dc8ff125c84..47ea2b866a93404 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
@@ -8,21 +8,30 @@ correct namespace.
 
 .. code-block:: c++
 
-// Correct: implementation inside the correct namespace.
-namespace __llvm_libc {
+// Implementation inside the LIBC_NAMESPACE namespace.
+// Correct if:
+// - LIBC_NAMESPACE is a macro
+// - LIBC_NAMESPACE expansion starts with `__llvm_libc`
+namespace LIBC_NAMESPACE {
 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
-// Namespaces within __llvm_libc namespace are allowed.
-namespace inner{
+// Namespaces within LIBC_NAMESPACE namespace are allowed.
+namespace inner {
 int localVar = 0;
 }
 // Functions with C linkage are allowed.
-extern "C" void str_fuzz(){}
+extern "C" void str_fuzz() {}
 }
 
-// Incorrect: implementation not in a namespace.
+// Incorrect: implementation not in the LIBC_NAMESPACE namespace.
 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
 
-// Incorrect: outer most namespace is not correct.
+// Incorrect: outer most namespace is not the LIBC_NAMESPACE macro.
 namespace something_else {
 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
 }
+
+// Incorrect: outer most namespace expansion does not start with 
`__llvm_libc`.
+#define LIBC_NAMESPACE custom_namespace
+namespace LIBC_NAMESPACE {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+}
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
index e75556a623b655c..16c5f9ca1067ec5 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
@@ -3

[clang-tools-extra] [clang-tidy] Update llvmlibc-implementation-in-namespace to new rules (PR #66504)

2023-09-21 Thread Guillaume Chatelet via cfe-commits


@@ -3,18 +3,18 @@
 #define MACRO_A "defining macros outside namespace is valid"
 
 class ClassB;
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration must be declared 
within the '__llvm_libc' namespace
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration must be declared 
within a namespace starting with '__llvm_libc'
 struct StructC {};
-// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: declaration must be declared 
within the '__llvm_libc' namespace
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: declaration must be declared 
within a namespace starting with '__llvm_libc'
 char *VarD = MACRO_A;
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration must be declared 
within the '__llvm_libc' namespace
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration must be declared 
within a namespace starting with '__llvm_libc'
 typedef int typeE;
-// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: declaration must be declared 
within the '__llvm_libc' namespace
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: declaration must be declared 
within a namespace starting with '__llvm_libc'
 void funcF() {}
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration must be declared 
within the '__llvm_libc' namespace
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration must be declared 
within a namespace starting with '__llvm_libc'
 

gchatelet wrote:

done

https://github.com/llvm/llvm-project/pull/66504
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Update llvmlibc-implementation-in-namespace to new rules (PR #66504)

2023-09-21 Thread Guillaume Chatelet via cfe-commits


@@ -30,15 +32,18 @@ void ImplementationInNamespaceCheck::check(
 return;

gchatelet wrote:

Done

https://github.com/llvm/llvm-project/pull/66504
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Update llvmlibc-implementation-in-namespace to new rules (PR #66504)

2023-09-21 Thread Guillaume Chatelet via cfe-commits

gchatelet wrote:

> As a single small change to make hardcoded namespaces configurable looks 
> fine. I added some comments related to overall issues in this check. Fell 
> free to fix them or ignore them.

Thx for the review! I had to restructure the code a bit to accommodate for 
anonymous namespaces (they generate an implict UsingDirectiveDecl that was 
triggering the warning twice).

Let me know what you think.

https://github.com/llvm/llvm-project/pull/66504
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Update llvmlibc-implementation-in-namespace to new rules (PR #66504)

2023-09-21 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet updated 
https://github.com/llvm/llvm-project/pull/66504

>From f1427a81c4a3425c1a574316fc26d2c74297b34b Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet 
Date: Fri, 15 Sep 2023 12:34:17 +
Subject: [PATCH 1/6] [clang-tidy] Update llvmlibc-implementation-in-namespace
 to new rules

This is the implementation of step 3 of
https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079.
---
 .../ImplementationInNamespaceCheck.cpp| 21 -
 .../llvmlibc/implementation-in-namespace.rst  | 23 +-
 .../llvmlibc/implementation-in-namespace.cpp  | 31 +--
 3 files changed, 50 insertions(+), 25 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp 
b/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
index d05310f09ef773a..69a385f5be9807f 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
@@ -14,7 +14,9 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::llvm_libc {
 
-const static StringRef RequiredNamespace = "__llvm_libc";
+const static StringRef RequiredNamespaceStart = "__llvm_libc";
+const static StringRef RequiredNamespaceMacroName = "LIBC_NAMESPACE";
+
 void ImplementationInNamespaceCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   decl(hasParent(translationUnitDecl()), unless(linkageSpecDecl()))
@@ -29,16 +31,19 @@ void ImplementationInNamespaceCheck::check(
   if (!Result.SourceManager->isInMainFile(MatchedDecl->getLocation()))
 return;
 
-  if (const auto *NS = dyn_cast(MatchedDecl)) {
-if (NS->getName() != RequiredNamespace) {
-  diag(NS->getLocation(), "'%0' needs to be the outermost namespace")
-  << RequiredNamespace;
-}
+  if (auto *NS = dyn_cast(MatchedDecl)) {
+if (!Result.SourceManager->isMacroBodyExpansion(NS->getLocation()))
+  diag(NS->getLocation(),
+   "the outermost namespace should be the '%0' macro")
+  << RequiredNamespaceMacroName;
+else if (!NS->getName().starts_with(RequiredNamespaceStart))
+  diag(NS->getLocation(), "the outermost namespace should start with '%0'")
+  << RequiredNamespaceStart;
 return;
   }
   diag(MatchedDecl->getLocation(),
-   "declaration must be declared within the '%0' namespace")
-  << RequiredNamespace;
+   "declaration must be declared within a namespace starting with '%0'")
+  << RequiredNamespaceStart;
 }
 
 } // namespace clang::tidy::llvm_libc
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
index 33d6dc8ff125c84..47ea2b866a93404 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
@@ -8,21 +8,30 @@ correct namespace.
 
 .. code-block:: c++
 
-// Correct: implementation inside the correct namespace.
-namespace __llvm_libc {
+// Implementation inside the LIBC_NAMESPACE namespace.
+// Correct if:
+// - LIBC_NAMESPACE is a macro
+// - LIBC_NAMESPACE expansion starts with `__llvm_libc`
+namespace LIBC_NAMESPACE {
 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
-// Namespaces within __llvm_libc namespace are allowed.
-namespace inner{
+// Namespaces within LIBC_NAMESPACE namespace are allowed.
+namespace inner {
 int localVar = 0;
 }
 // Functions with C linkage are allowed.
-extern "C" void str_fuzz(){}
+extern "C" void str_fuzz() {}
 }
 
-// Incorrect: implementation not in a namespace.
+// Incorrect: implementation not in the LIBC_NAMESPACE namespace.
 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
 
-// Incorrect: outer most namespace is not correct.
+// Incorrect: outer most namespace is not the LIBC_NAMESPACE macro.
 namespace something_else {
 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
 }
+
+// Incorrect: outer most namespace expansion does not start with 
`__llvm_libc`.
+#define LIBC_NAMESPACE custom_namespace
+namespace LIBC_NAMESPACE {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+}
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
index e75556a623b655c..16c5f9ca1067ec5 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
@@ -3

[clang-tools-extra] [clang-tidy] Update llvmlibc-implementation-in-namespace to new rules (PR #66504)

2023-09-21 Thread Guillaume Chatelet via cfe-commits


@@ -18,32 +18,32 @@ const static StringRef RequiredNamespaceStart = 
"__llvm_libc";
 const static StringRef RequiredNamespaceMacroName = "LIBC_NAMESPACE";
 
 void ImplementationInNamespaceCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(
-  decl(hasParent(translationUnitDecl()), unless(linkageSpecDecl()))
-  .bind("child_of_translation_unit"),
-  this);
+  Finder->addMatcher(decl(isExpansionInMainFile(),
+  hasDeclContext(translationUnitDecl()),
+  unless(linkageSpecDecl()))
+ .bind("child_of_translation_unit"),
+ this);
 }
 
 void ImplementationInNamespaceCheck::check(
 const MatchFinder::MatchResult &Result) {
   const auto *MatchedDecl =
   Result.Nodes.getNodeAs("child_of_translation_unit");
-  if (!Result.SourceManager->isInMainFile(MatchedDecl->getLocation()))
-return;
 
   if (const auto *NS = dyn_cast(MatchedDecl)) {
 if (!Result.SourceManager->isMacroBodyExpansion(NS->getLocation()))
   diag(NS->getLocation(),
"the outermost namespace should be the '%0' macro")
   << RequiredNamespaceMacroName;
-else if (!NS->getName().starts_with(RequiredNamespaceStart))
+else if (NS->isAnonymousNamespace() ||

gchatelet wrote:

Yeah anonymous namespaces are not allowed.

https://github.com/llvm/llvm-project/pull/66504
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Update llvmlibc-implementation-in-namespace to new rules (PR #66504)

2023-09-21 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet closed 
https://github.com/llvm/llvm-project/pull/66504
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][libc] Fix namespace check with macro (PR #68134)

2023-10-04 Thread Guillaume Chatelet via cfe-commits

gchatelet wrote:

It would be ideal to move the [following lines](
https://github.com/llvm/llvm-project/blob/b3c710beda5b45dc18a5cbd74e141c1169971450/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp#L17-L18)
  to a shared header and use them in both implementations.

https://github.com/llvm/llvm-project/pull/68134
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][libc] Fix namespace check with macro (PR #68134)

2023-10-06 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet approved this pull request.


https://github.com/llvm/llvm-project/pull/68134
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] Add invoke / invoke_result type traits (PR #65750)

2023-09-14 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet updated 
https://github.com/llvm/llvm-project/pull/65750:

>From 5023264dce58aaa46b18404a4578b7a777962758 Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet 
Date: Fri, 8 Sep 2023 13:10:05 +
Subject: [PATCH 1/4] [libc] add invoke / invoke_result type traits

---
 libc/src/__support/CPP/CMakeLists.txt |  2 +
 libc/src/__support/CPP/type_traits.h  |  2 +
 libc/src/__support/CPP/type_traits/invoke.h   | 58 +
 .../__support/CPP/type_traits/invoke_result.h | 26 ++
 .../src/__support/CPP/type_traits_test.cpp| 86 +++
 .../llvm-project-overlay/libc/BUILD.bazel |  3 +
 6 files changed, 177 insertions(+)
 create mode 100644 libc/src/__support/CPP/type_traits/invoke.h
 create mode 100644 libc/src/__support/CPP/type_traits/invoke_result.h

diff --git a/libc/src/__support/CPP/CMakeLists.txt 
b/libc/src/__support/CPP/CMakeLists.txt
index d24c023ec28ebc9..bb330a7b0ac5106 100644
--- a/libc/src/__support/CPP/CMakeLists.txt
+++ b/libc/src/__support/CPP/CMakeLists.txt
@@ -104,6 +104,8 @@ add_header_library(
 type_traits/enable_if.h
 type_traits/false_type.h
 type_traits/integral_constant.h
+type_traits/invoke.h
+type_traits/invoke_result.h
 type_traits/is_arithmetic.h
 type_traits/is_array.h
 type_traits/is_base_of.h
diff --git a/libc/src/__support/CPP/type_traits.h 
b/libc/src/__support/CPP/type_traits.h
index 9deb08b221593e1..3de2ca58903184c 100644
--- a/libc/src/__support/CPP/type_traits.h
+++ b/libc/src/__support/CPP/type_traits.h
@@ -18,6 +18,8 @@
 #include "src/__support/CPP/type_traits/enable_if.h"
 #include "src/__support/CPP/type_traits/false_type.h"
 #include "src/__support/CPP/type_traits/integral_constant.h"
+#include "src/__support/CPP/type_traits/invoke.h"
+#include "src/__support/CPP/type_traits/invoke_result.h"
 #include "src/__support/CPP/type_traits/is_arithmetic.h"
 #include "src/__support/CPP/type_traits/is_array.h"
 #include "src/__support/CPP/type_traits/is_base_of.h"
diff --git a/libc/src/__support/CPP/type_traits/invoke.h 
b/libc/src/__support/CPP/type_traits/invoke.h
new file mode 100644
index 000..e1f661339f349e7
--- /dev/null
+++ b/libc/src/__support/CPP/type_traits/invoke.h
@@ -0,0 +1,58 @@
+//===-- invoke type_traits --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INVOKE_H
+#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INVOKE_H
+
+#include "src/__support/CPP/type_traits/decay.h"
+#include "src/__support/CPP/type_traits/is_base_of.h"
+#include "src/__support/CPP/utility/forward.h"
+
+// BEWARE : this implementation is not fully conformant as it doesn't take
+// `cpp::reference_wrapper` into account.
+
+namespace __llvm_libc::cpp {
+
+namespace detail {
+
+// Catch all function types.
+template  struct invoke_dispatcher {
+  template 
+  static auto call(FunctionPtrType &&fun, Args &&...args) {
+return cpp::forward(fun)(cpp::forward(args)...);
+  }
+};
+
+// Catch pointer to member function types.
+template 
+struct invoke_dispatcher {
+  using FunctionPtrType = FunctionReturnType Class::*;
+
+  template >
+  static auto call(FunctionPtrType fun, T &&t1, Args &&...args) {
+if constexpr (cpp::is_base_of_v) {
+  // T is a (possibly cv ref) type.
+  return (cpp::forward(t1).*fun)(cpp::forward(args)...);
+} else {
+  // T is assumed to be a pointer type.
+  return (*cpp::forward(t1).*fun)(cpp::forward(args)...);
+}
+  }
+};
+
+} // namespace detail
+
+template 
+auto invoke(Function &&fun, Args &&...args) {
+  return detail::invoke_dispatcher>::call(
+  cpp::forward(fun), cpp::forward(args)...);
+}
+
+} // namespace __llvm_libc::cpp
+
+#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INVOKE_H
diff --git a/libc/src/__support/CPP/type_traits/invoke_result.h 
b/libc/src/__support/CPP/type_traits/invoke_result.h
new file mode 100644
index 000..1a071f5cb94836f
--- /dev/null
+++ b/libc/src/__support/CPP/type_traits/invoke_result.h
@@ -0,0 +1,26 @@
+//===-- invoke_result type_traits ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INVOKE_RESULT_H
+#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INVOKE_RESULT_H
+
+#include "src/__support/CPP/type_traits/invoke.h"
+#include "src/__support/CPP/utility/declval.h"
+
+namespace __llvm_libc::cpp {
+
+template  st

[clang-tools-extra] [libc] Add invoke / invoke_result type traits (PR #65750)

2023-09-14 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet updated 
https://github.com/llvm/llvm-project/pull/65750:

>From 5023264dce58aaa46b18404a4578b7a777962758 Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet 
Date: Fri, 8 Sep 2023 13:10:05 +
Subject: [PATCH 1/4] [libc] add invoke / invoke_result type traits

---
 libc/src/__support/CPP/CMakeLists.txt |  2 +
 libc/src/__support/CPP/type_traits.h  |  2 +
 libc/src/__support/CPP/type_traits/invoke.h   | 58 +
 .../__support/CPP/type_traits/invoke_result.h | 26 ++
 .../src/__support/CPP/type_traits_test.cpp| 86 +++
 .../llvm-project-overlay/libc/BUILD.bazel |  3 +
 6 files changed, 177 insertions(+)
 create mode 100644 libc/src/__support/CPP/type_traits/invoke.h
 create mode 100644 libc/src/__support/CPP/type_traits/invoke_result.h

diff --git a/libc/src/__support/CPP/CMakeLists.txt 
b/libc/src/__support/CPP/CMakeLists.txt
index d24c023ec28ebc9..bb330a7b0ac5106 100644
--- a/libc/src/__support/CPP/CMakeLists.txt
+++ b/libc/src/__support/CPP/CMakeLists.txt
@@ -104,6 +104,8 @@ add_header_library(
 type_traits/enable_if.h
 type_traits/false_type.h
 type_traits/integral_constant.h
+type_traits/invoke.h
+type_traits/invoke_result.h
 type_traits/is_arithmetic.h
 type_traits/is_array.h
 type_traits/is_base_of.h
diff --git a/libc/src/__support/CPP/type_traits.h 
b/libc/src/__support/CPP/type_traits.h
index 9deb08b221593e1..3de2ca58903184c 100644
--- a/libc/src/__support/CPP/type_traits.h
+++ b/libc/src/__support/CPP/type_traits.h
@@ -18,6 +18,8 @@
 #include "src/__support/CPP/type_traits/enable_if.h"
 #include "src/__support/CPP/type_traits/false_type.h"
 #include "src/__support/CPP/type_traits/integral_constant.h"
+#include "src/__support/CPP/type_traits/invoke.h"
+#include "src/__support/CPP/type_traits/invoke_result.h"
 #include "src/__support/CPP/type_traits/is_arithmetic.h"
 #include "src/__support/CPP/type_traits/is_array.h"
 #include "src/__support/CPP/type_traits/is_base_of.h"
diff --git a/libc/src/__support/CPP/type_traits/invoke.h 
b/libc/src/__support/CPP/type_traits/invoke.h
new file mode 100644
index 000..e1f661339f349e7
--- /dev/null
+++ b/libc/src/__support/CPP/type_traits/invoke.h
@@ -0,0 +1,58 @@
+//===-- invoke type_traits --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INVOKE_H
+#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INVOKE_H
+
+#include "src/__support/CPP/type_traits/decay.h"
+#include "src/__support/CPP/type_traits/is_base_of.h"
+#include "src/__support/CPP/utility/forward.h"
+
+// BEWARE : this implementation is not fully conformant as it doesn't take
+// `cpp::reference_wrapper` into account.
+
+namespace __llvm_libc::cpp {
+
+namespace detail {
+
+// Catch all function types.
+template  struct invoke_dispatcher {
+  template 
+  static auto call(FunctionPtrType &&fun, Args &&...args) {
+return cpp::forward(fun)(cpp::forward(args)...);
+  }
+};
+
+// Catch pointer to member function types.
+template 
+struct invoke_dispatcher {
+  using FunctionPtrType = FunctionReturnType Class::*;
+
+  template >
+  static auto call(FunctionPtrType fun, T &&t1, Args &&...args) {
+if constexpr (cpp::is_base_of_v) {
+  // T is a (possibly cv ref) type.
+  return (cpp::forward(t1).*fun)(cpp::forward(args)...);
+} else {
+  // T is assumed to be a pointer type.
+  return (*cpp::forward(t1).*fun)(cpp::forward(args)...);
+}
+  }
+};
+
+} // namespace detail
+
+template 
+auto invoke(Function &&fun, Args &&...args) {
+  return detail::invoke_dispatcher>::call(
+  cpp::forward(fun), cpp::forward(args)...);
+}
+
+} // namespace __llvm_libc::cpp
+
+#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INVOKE_H
diff --git a/libc/src/__support/CPP/type_traits/invoke_result.h 
b/libc/src/__support/CPP/type_traits/invoke_result.h
new file mode 100644
index 000..1a071f5cb94836f
--- /dev/null
+++ b/libc/src/__support/CPP/type_traits/invoke_result.h
@@ -0,0 +1,26 @@
+//===-- invoke_result type_traits ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INVOKE_RESULT_H
+#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INVOKE_RESULT_H
+
+#include "src/__support/CPP/type_traits/invoke.h"
+#include "src/__support/CPP/utility/declval.h"
+
+namespace __llvm_libc::cpp {
+
+template  st

[clang] [libc] Add invoke / invoke_result type traits (PR #65750)

2023-09-14 Thread Guillaume Chatelet via cfe-commits


@@ -0,0 +1,26 @@
+//===-- invoke_result type_traits ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INVOKE_RESULT_H
+#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INVOKE_RESULT_H
+
+#include "src/__support/CPP/type_traits/invoke.h"
+#include "src/__support/CPP/utility/declval.h"
+
+namespace __llvm_libc::cpp {
+
+template  struct invoke_result {
+  using type =
+  decltype(cpp::invoke(cpp::declval(), cpp::declval()...));

gchatelet wrote:

FTR this has been discussed off line.

https://github.com/llvm/llvm-project/pull/65750
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] Add invoke / invoke_result type traits (PR #65750)

2023-09-14 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet review_requested 
https://github.com/llvm/llvm-project/pull/65750
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] Add invoke / invoke_result type traits (PR #65750)

2023-09-14 Thread Guillaume Chatelet via cfe-commits


@@ -0,0 +1,26 @@
+//===-- invoke_result type_traits ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INVOKE_RESULT_H
+#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INVOKE_RESULT_H
+
+#include "src/__support/CPP/type_traits/invoke.h"
+#include "src/__support/CPP/utility/declval.h"
+
+namespace __llvm_libc::cpp {
+
+template  struct invoke_result {
+  using type =
+  decltype(cpp::invoke(cpp::declval(), cpp::declval()...));

gchatelet wrote:

FTR this has been discussed off line.

https://github.com/llvm/llvm-project/pull/65750
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] Add invoke / invoke_result type traits (PR #65750)

2023-09-14 Thread Guillaume Chatelet via cfe-commits


@@ -0,0 +1,59 @@
+//===-- invoke type_traits --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INVOKE_H
+#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INVOKE_H
+
+#include "src/__support/CPP/type_traits/decay.h"
+#include "src/__support/CPP/type_traits/enable_if.h"
+#include "src/__support/CPP/type_traits/is_base_of.h"
+#include "src/__support/CPP/type_traits/is_same.h"
+#include "src/__support/CPP/utility/forward.h"
+
+namespace __llvm_libc::cpp {
+
+namespace detail {
+
+// Catch all function and functor types.
+template  struct invoke_dispatcher {
+  template , FunctionPtrType>>>
+  static auto call(T &&fun, Args &&...args) {
+return cpp::forward(fun)(cpp::forward(args)...);
+  }
+};
+
+// Catch pointer to member function types.
+template 
+struct invoke_dispatcher {
+  using FunctionPtrType = FunctionReturnType Class::*;
+
+  template >
+  static auto call(FunctionPtrType fun, T &&t1, Args &&...args) {
+if constexpr (cpp::is_base_of_v) {
+  // T is a (possibly cv ref) type.
+  return (cpp::forward(t1).*fun)(cpp::forward(args)...);
+} else {
+  // T is assumed to be a pointer type.

gchatelet wrote:

Done

https://github.com/llvm/llvm-project/pull/65750
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] Add invoke / invoke_result type traits (PR #65750)

2023-09-14 Thread Guillaume Chatelet via cfe-commits


@@ -0,0 +1,59 @@
+//===-- invoke type_traits --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INVOKE_H
+#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INVOKE_H
+
+#include "src/__support/CPP/type_traits/decay.h"
+#include "src/__support/CPP/type_traits/enable_if.h"
+#include "src/__support/CPP/type_traits/is_base_of.h"
+#include "src/__support/CPP/type_traits/is_same.h"
+#include "src/__support/CPP/utility/forward.h"
+
+namespace __llvm_libc::cpp {
+
+namespace detail {
+
+// Catch all function and functor types.
+template  struct invoke_dispatcher {
+  template , FunctionPtrType>>>
+  static auto call(T &&fun, Args &&...args) {
+return cpp::forward(fun)(cpp::forward(args)...);
+  }
+};
+
+// Catch pointer to member function types.
+template 
+struct invoke_dispatcher {
+  using FunctionPtrType = FunctionReturnType Class::*;
+
+  template >
+  static auto call(FunctionPtrType fun, T &&t1, Args &&...args) {
+if constexpr (cpp::is_base_of_v) {
+  // T is a (possibly cv ref) type.
+  return (cpp::forward(t1).*fun)(cpp::forward(args)...);
+} else {
+  // T is assumed to be a pointer type.

gchatelet wrote:

Done

https://github.com/llvm/llvm-project/pull/65750
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] Add invoke / invoke_result type traits (PR #65750)

2023-09-14 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet edited 
https://github.com/llvm/llvm-project/pull/65750
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] Add invoke / invoke_result type traits (PR #65750)

2023-09-14 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet edited 
https://github.com/llvm/llvm-project/pull/65750
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] Add invoke / invoke_result type traits (PR #65750)

2023-09-14 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet resolved 
https://github.com/llvm/llvm-project/pull/65750
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] Add invoke / invoke_result type traits (PR #65750)

2023-09-14 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet resolved 
https://github.com/llvm/llvm-project/pull/65750
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] Add invoke / invoke_result type traits (PR #65750)

2023-09-15 Thread Guillaume Chatelet via cfe-commits

gchatelet wrote:

Thx for the thorough review @legrosbuffle, I really appreciate it.

https://github.com/llvm/llvm-project/pull/65750
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] Add invoke / invoke_result type traits (PR #65750)

2023-09-15 Thread Guillaume Chatelet via cfe-commits

gchatelet wrote:

Thx for the thorough review @legrosbuffle, I really appreciate it.

https://github.com/llvm/llvm-project/pull/65750
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] Add invoke / invoke_result type traits (PR #65750)

2023-09-15 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet closed 
https://github.com/llvm/llvm-project/pull/65750
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] Add invoke / invoke_result type traits (PR #65750)

2023-09-15 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet closed 
https://github.com/llvm/llvm-project/pull/65750
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Update llvmlibc-implementation-in-namespace to new rules (PR #66504)

2023-09-15 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet created 
https://github.com/llvm/llvm-project/pull/66504

This is the implementation of step 3 of
https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079.


>From f1427a81c4a3425c1a574316fc26d2c74297b34b Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet 
Date: Fri, 15 Sep 2023 12:34:17 +
Subject: [PATCH] [clang-tidy] Update llvmlibc-implementation-in-namespace to
 new rules

This is the implementation of step 3 of
https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079.
---
 .../ImplementationInNamespaceCheck.cpp| 21 -
 .../llvmlibc/implementation-in-namespace.rst  | 23 +-
 .../llvmlibc/implementation-in-namespace.cpp  | 31 +--
 3 files changed, 50 insertions(+), 25 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp 
b/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
index d05310f09ef773a..69a385f5be9807f 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
@@ -14,7 +14,9 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::llvm_libc {
 
-const static StringRef RequiredNamespace = "__llvm_libc";
+const static StringRef RequiredNamespaceStart = "__llvm_libc";
+const static StringRef RequiredNamespaceMacroName = "LIBC_NAMESPACE";
+
 void ImplementationInNamespaceCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   decl(hasParent(translationUnitDecl()), unless(linkageSpecDecl()))
@@ -29,16 +31,19 @@ void ImplementationInNamespaceCheck::check(
   if (!Result.SourceManager->isInMainFile(MatchedDecl->getLocation()))
 return;
 
-  if (const auto *NS = dyn_cast(MatchedDecl)) {
-if (NS->getName() != RequiredNamespace) {
-  diag(NS->getLocation(), "'%0' needs to be the outermost namespace")
-  << RequiredNamespace;
-}
+  if (auto *NS = dyn_cast(MatchedDecl)) {
+if (!Result.SourceManager->isMacroBodyExpansion(NS->getLocation()))
+  diag(NS->getLocation(),
+   "the outermost namespace should be the '%0' macro")
+  << RequiredNamespaceMacroName;
+else if (!NS->getName().starts_with(RequiredNamespaceStart))
+  diag(NS->getLocation(), "the outermost namespace should start with '%0'")
+  << RequiredNamespaceStart;
 return;
   }
   diag(MatchedDecl->getLocation(),
-   "declaration must be declared within the '%0' namespace")
-  << RequiredNamespace;
+   "declaration must be declared within a namespace starting with '%0'")
+  << RequiredNamespaceStart;
 }
 
 } // namespace clang::tidy::llvm_libc
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
index 33d6dc8ff125c84..47ea2b866a93404 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
@@ -8,21 +8,30 @@ correct namespace.
 
 .. code-block:: c++
 
-// Correct: implementation inside the correct namespace.
-namespace __llvm_libc {
+// Implementation inside the LIBC_NAMESPACE namespace.
+// Correct if:
+// - LIBC_NAMESPACE is a macro
+// - LIBC_NAMESPACE expansion starts with `__llvm_libc`
+namespace LIBC_NAMESPACE {
 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
-// Namespaces within __llvm_libc namespace are allowed.
-namespace inner{
+// Namespaces within LIBC_NAMESPACE namespace are allowed.
+namespace inner {
 int localVar = 0;
 }
 // Functions with C linkage are allowed.
-extern "C" void str_fuzz(){}
+extern "C" void str_fuzz() {}
 }
 
-// Incorrect: implementation not in a namespace.
+// Incorrect: implementation not in the LIBC_NAMESPACE namespace.
 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
 
-// Incorrect: outer most namespace is not correct.
+// Incorrect: outer most namespace is not the LIBC_NAMESPACE macro.
 namespace something_else {
 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
 }
+
+// Incorrect: outer most namespace expansion does not start with 
`__llvm_libc`.
+#define LIBC_NAMESPACE custom_namespace
+namespace LIBC_NAMESPACE {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+}
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
index e75556a623b655c..16c5f9ca1067ec5 100644
--- 
a/clang-tools-e

[clang-tools-extra] [clang-tidy] Update llvmlibc-implementation-in-namespace to new rules (PR #66504)

2023-09-18 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet updated 
https://github.com/llvm/llvm-project/pull/66504

>From f1427a81c4a3425c1a574316fc26d2c74297b34b Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet 
Date: Fri, 15 Sep 2023 12:34:17 +
Subject: [PATCH 1/2] [clang-tidy] Update llvmlibc-implementation-in-namespace
 to new rules

This is the implementation of step 3 of
https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079.
---
 .../ImplementationInNamespaceCheck.cpp| 21 -
 .../llvmlibc/implementation-in-namespace.rst  | 23 +-
 .../llvmlibc/implementation-in-namespace.cpp  | 31 +--
 3 files changed, 50 insertions(+), 25 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp 
b/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
index d05310f09ef773a..69a385f5be9807f 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
@@ -14,7 +14,9 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::llvm_libc {
 
-const static StringRef RequiredNamespace = "__llvm_libc";
+const static StringRef RequiredNamespaceStart = "__llvm_libc";
+const static StringRef RequiredNamespaceMacroName = "LIBC_NAMESPACE";
+
 void ImplementationInNamespaceCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   decl(hasParent(translationUnitDecl()), unless(linkageSpecDecl()))
@@ -29,16 +31,19 @@ void ImplementationInNamespaceCheck::check(
   if (!Result.SourceManager->isInMainFile(MatchedDecl->getLocation()))
 return;
 
-  if (const auto *NS = dyn_cast(MatchedDecl)) {
-if (NS->getName() != RequiredNamespace) {
-  diag(NS->getLocation(), "'%0' needs to be the outermost namespace")
-  << RequiredNamespace;
-}
+  if (auto *NS = dyn_cast(MatchedDecl)) {
+if (!Result.SourceManager->isMacroBodyExpansion(NS->getLocation()))
+  diag(NS->getLocation(),
+   "the outermost namespace should be the '%0' macro")
+  << RequiredNamespaceMacroName;
+else if (!NS->getName().starts_with(RequiredNamespaceStart))
+  diag(NS->getLocation(), "the outermost namespace should start with '%0'")
+  << RequiredNamespaceStart;
 return;
   }
   diag(MatchedDecl->getLocation(),
-   "declaration must be declared within the '%0' namespace")
-  << RequiredNamespace;
+   "declaration must be declared within a namespace starting with '%0'")
+  << RequiredNamespaceStart;
 }
 
 } // namespace clang::tidy::llvm_libc
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
index 33d6dc8ff125c84..47ea2b866a93404 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
@@ -8,21 +8,30 @@ correct namespace.
 
 .. code-block:: c++
 
-// Correct: implementation inside the correct namespace.
-namespace __llvm_libc {
+// Implementation inside the LIBC_NAMESPACE namespace.
+// Correct if:
+// - LIBC_NAMESPACE is a macro
+// - LIBC_NAMESPACE expansion starts with `__llvm_libc`
+namespace LIBC_NAMESPACE {
 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
-// Namespaces within __llvm_libc namespace are allowed.
-namespace inner{
+// Namespaces within LIBC_NAMESPACE namespace are allowed.
+namespace inner {
 int localVar = 0;
 }
 // Functions with C linkage are allowed.
-extern "C" void str_fuzz(){}
+extern "C" void str_fuzz() {}
 }
 
-// Incorrect: implementation not in a namespace.
+// Incorrect: implementation not in the LIBC_NAMESPACE namespace.
 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
 
-// Incorrect: outer most namespace is not correct.
+// Incorrect: outer most namespace is not the LIBC_NAMESPACE macro.
 namespace something_else {
 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
 }
+
+// Incorrect: outer most namespace expansion does not start with 
`__llvm_libc`.
+#define LIBC_NAMESPACE custom_namespace
+namespace LIBC_NAMESPACE {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+}
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
index e75556a623b655c..16c5f9ca1067ec5 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
@@ -3

[clang-tools-extra] [clang-tidy] Update llvmlibc-implementation-in-namespace to new rules (PR #66504)

2023-09-18 Thread Guillaume Chatelet via cfe-commits

gchatelet wrote:

> Should this change be reflected in the Release Notes?

Where would that be? `clang-tools-extra/docs/ReleaseNotes.rst`?
I can't find what the current release notes look like for head.

https://github.com/llvm/llvm-project/pull/66504
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Update llvmlibc-implementation-in-namespace to new rules (PR #66504)

2023-09-18 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet updated 
https://github.com/llvm/llvm-project/pull/66504

>From f1427a81c4a3425c1a574316fc26d2c74297b34b Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet 
Date: Fri, 15 Sep 2023 12:34:17 +
Subject: [PATCH 1/3] [clang-tidy] Update llvmlibc-implementation-in-namespace
 to new rules

This is the implementation of step 3 of
https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079.
---
 .../ImplementationInNamespaceCheck.cpp| 21 -
 .../llvmlibc/implementation-in-namespace.rst  | 23 +-
 .../llvmlibc/implementation-in-namespace.cpp  | 31 +--
 3 files changed, 50 insertions(+), 25 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp 
b/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
index d05310f09ef773a..69a385f5be9807f 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
@@ -14,7 +14,9 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::llvm_libc {
 
-const static StringRef RequiredNamespace = "__llvm_libc";
+const static StringRef RequiredNamespaceStart = "__llvm_libc";
+const static StringRef RequiredNamespaceMacroName = "LIBC_NAMESPACE";
+
 void ImplementationInNamespaceCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   decl(hasParent(translationUnitDecl()), unless(linkageSpecDecl()))
@@ -29,16 +31,19 @@ void ImplementationInNamespaceCheck::check(
   if (!Result.SourceManager->isInMainFile(MatchedDecl->getLocation()))
 return;
 
-  if (const auto *NS = dyn_cast(MatchedDecl)) {
-if (NS->getName() != RequiredNamespace) {
-  diag(NS->getLocation(), "'%0' needs to be the outermost namespace")
-  << RequiredNamespace;
-}
+  if (auto *NS = dyn_cast(MatchedDecl)) {
+if (!Result.SourceManager->isMacroBodyExpansion(NS->getLocation()))
+  diag(NS->getLocation(),
+   "the outermost namespace should be the '%0' macro")
+  << RequiredNamespaceMacroName;
+else if (!NS->getName().starts_with(RequiredNamespaceStart))
+  diag(NS->getLocation(), "the outermost namespace should start with '%0'")
+  << RequiredNamespaceStart;
 return;
   }
   diag(MatchedDecl->getLocation(),
-   "declaration must be declared within the '%0' namespace")
-  << RequiredNamespace;
+   "declaration must be declared within a namespace starting with '%0'")
+  << RequiredNamespaceStart;
 }
 
 } // namespace clang::tidy::llvm_libc
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
index 33d6dc8ff125c84..47ea2b866a93404 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst
@@ -8,21 +8,30 @@ correct namespace.
 
 .. code-block:: c++
 
-// Correct: implementation inside the correct namespace.
-namespace __llvm_libc {
+// Implementation inside the LIBC_NAMESPACE namespace.
+// Correct if:
+// - LIBC_NAMESPACE is a macro
+// - LIBC_NAMESPACE expansion starts with `__llvm_libc`
+namespace LIBC_NAMESPACE {
 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
-// Namespaces within __llvm_libc namespace are allowed.
-namespace inner{
+// Namespaces within LIBC_NAMESPACE namespace are allowed.
+namespace inner {
 int localVar = 0;
 }
 // Functions with C linkage are allowed.
-extern "C" void str_fuzz(){}
+extern "C" void str_fuzz() {}
 }
 
-// Incorrect: implementation not in a namespace.
+// Incorrect: implementation not in the LIBC_NAMESPACE namespace.
 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
 
-// Incorrect: outer most namespace is not correct.
+// Incorrect: outer most namespace is not the LIBC_NAMESPACE macro.
 namespace something_else {
 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
 }
+
+// Incorrect: outer most namespace expansion does not start with 
`__llvm_libc`.
+#define LIBC_NAMESPACE custom_namespace
+namespace LIBC_NAMESPACE {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+}
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
index e75556a623b655c..16c5f9ca1067ec5 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp
@@ -3

[clang] d260a10 - [clang] Fix crash during template sema checking

2020-03-21 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2020-03-21T12:42:06+01:00
New Revision: d260a10d98dff6e34d081e570df1f7c0a50b9a73

URL: 
https://github.com/llvm/llvm-project/commit/d260a10d98dff6e34d081e570df1f7c0a50b9a73
DIFF: 
https://github.com/llvm/llvm-project/commit/d260a10d98dff6e34d081e570df1f7c0a50b9a73.diff

LOG: [clang] Fix crash during template sema checking

Summary: If the size parameter of `__builtin_memcpy_inline` comes from an 
un-instantiated template parameter current code would crash.

Reviewers: efriedma, courbet

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76504

Added: 
clang/test/Sema/builtins-memcpy-inline.cpp

Modified: 
clang/lib/Sema/SemaChecking.cpp

Removed: 
clang/test/Sema/builtins-memcpy-inline.c



diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 8a2b4b019663..c3e168c1e736 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -1649,11 +1649,16 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
   case Builtin::BI__builtin_nontemporal_store:
 return SemaBuiltinNontemporalOverloaded(TheCallResult);
   case Builtin::BI__builtin_memcpy_inline: {
-// __builtin_memcpy_inline size argument is a constant by definition.
-if (TheCall->getArg(2)->EvaluateKnownConstInt(Context).isNullValue())
+clang::Expr *SizeOp = TheCall->getArg(2);
+// We warn about copying to or from `nullptr` pointers when `size` is
+// greater than 0. When `size` is value dependent we cannot evaluate its
+// value so we bail out.
+if (SizeOp->isValueDependent())
   break;
-CheckNonNullArgument(*this, TheCall->getArg(0), TheCall->getExprLoc());
-CheckNonNullArgument(*this, TheCall->getArg(1), TheCall->getExprLoc());
+if (!SizeOp->EvaluateKnownConstInt(Context).isNullValue()) {
+  CheckNonNullArgument(*this, TheCall->getArg(0), TheCall->getExprLoc());
+  CheckNonNullArgument(*this, TheCall->getArg(1), TheCall->getExprLoc());
+}
 break;
   }
 #define BUILTIN(ID, TYPE, ATTRS)

diff  --git a/clang/test/Sema/builtins-memcpy-inline.c 
b/clang/test/Sema/builtins-memcpy-inline.cpp
similarity index 86%
rename from clang/test/Sema/builtins-memcpy-inline.c
rename to clang/test/Sema/builtins-memcpy-inline.cpp
index 6d0edce92a11..5e03a975a71b 100644
--- a/clang/test/Sema/builtins-memcpy-inline.c
+++ b/clang/test/Sema/builtins-memcpy-inline.cpp
@@ -30,3 +30,9 @@ void 
test_memcpy_inline_null_buffer_is_ok_if_size_is_zero(void *ptr) {
 void test_memcpy_inline_non_constant_size(void *dst, const void *src, unsigned 
size) {
   __builtin_memcpy_inline(dst, src, size); // expected-error {{argument to 
'__builtin_memcpy_inline' must be a constant integer}}
 }
+
+template 
+void test_memcpy_inline_template(void *dst, const void *src) {
+  // we do not try to evaluate size in non intantiated templates.
+  __builtin_memcpy_inline(dst, src, size);
+}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1b2842b - [Alignment][NFC] CreateMemSet use MaybeAlign

2019-12-10 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2019-12-10T15:17:44+01:00
New Revision: 1b2842bf902a8b52acbef2425120533b63be5ae3

URL: 
https://github.com/llvm/llvm-project/commit/1b2842bf902a8b52acbef2425120533b63be5ae3
DIFF: 
https://github.com/llvm/llvm-project/commit/1b2842bf902a8b52acbef2425120533b63be5ae3.diff

LOG: [Alignment][NFC] CreateMemSet use MaybeAlign

Summary:
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

Reviewers: courbet

Subscribers: arsenm, jvesely, nhaehnle, hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D71213

Added: 


Modified: 
clang/lib/CodeGen/CGAtomic.cpp
clang/lib/CodeGen/CGBuilder.h
clang/lib/CodeGen/CGBuiltin.cpp
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/IR/Core.cpp
llvm/lib/IR/IRBuilder.cpp
llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index d07aaf58681c..149982d82790 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -350,7 +350,7 @@ bool AtomicInfo::emitMemSetZeroIfNecessary() const {
   CGF.Builder.CreateMemSet(
   addr, llvm::ConstantInt::get(CGF.Int8Ty, 0),
   CGF.getContext().toCharUnitsFromBits(AtomicSizeInBits).getQuantity(),
-  LVal.getAlignment().getQuantity());
+  LVal.getAlignment().getAsAlign());
   return true;
 }
 

diff  --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h
index dae3fbbc4b9f..746053f43e36 100644
--- a/clang/lib/CodeGen/CGBuilder.h
+++ b/clang/lib/CodeGen/CGBuilder.h
@@ -296,7 +296,7 @@ class CGBuilderTy : public CGBuilderBaseTy {
   llvm::CallInst *CreateMemSet(Address Dest, llvm::Value *Value,
llvm::Value *Size, bool IsVolatile = false) {
 return CreateMemSet(Dest.getPointer(), Value, Size,
-Dest.getAlignment().getQuantity(), IsVolatile);
+Dest.getAlignment().getAsAlign(), IsVolatile);
   }
 
   using CGBuilderBaseTy::CreatePreserveStructAccessIndex;

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7447a5841599..2b2738252a05 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -46,7 +46,8 @@ int64_t clamp(int64_t Value, int64_t Low, int64_t High) {
   return std::min(High, std::max(Low, Value));
 }
 
-static void initializeAlloca(CodeGenFunction &CGF, AllocaInst *AI, Value 
*Size, unsigned AlignmentInBytes) {
+static void initializeAlloca(CodeGenFunction &CGF, AllocaInst *AI, Value *Size,
+ Align AlignmentInBytes) {
   ConstantInt *Byte;
   switch (CGF.getLangOpts().getTrivialAutoVarInit()) {
   case LangOptions::TrivialAutoVarInitKind::Uninitialized:
@@ -2359,12 +2360,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 Value *Size = EmitScalarExpr(E->getArg(0));
 const TargetInfo &TI = getContext().getTargetInfo();
 // The alignment of the alloca should correspond to __BIGGEST_ALIGNMENT__.
-unsigned SuitableAlignmentInBytes =
+const Align SuitableAlignmentInBytes =
 CGM.getContext()
 .toCharUnitsFromBits(TI.getSuitableAlign())
-.getQuantity();
+.getAsAlign();
 AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
-AI->setAlignment(MaybeAlign(SuitableAlignmentInBytes));
+AI->setAlignment(SuitableAlignmentInBytes);
 initializeAlloca(*this, AI, Size, SuitableAlignmentInBytes);
 return RValue::get(AI);
   }
@@ -2374,10 +2375,10 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 Value *AlignmentInBitsValue = EmitScalarExpr(E->getArg(1));
 auto *AlignmentInBitsCI = cast(AlignmentInBitsValue);
 unsigned AlignmentInBits = AlignmentInBitsCI->getZExtValue();
-unsigned AlignmentInBytes =
-CGM.getContext().toCharUnitsFromBits(AlignmentInBits).getQuantity();
+const Align AlignmentInBytes =
+CGM.getContext().toCharUnitsFromBits(AlignmentInBits).getAsAlign();
 AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
-AI->setAlignment(MaybeAlign(AlignmentInBytes));
+AI->setAlignment(AlignmentInBytes);
 initializeAlloca(*this, AI, Size, AlignmentInBytes);
 return RValue::get

[clang] dbc5acf - [Alignment][NFC] Adding Align compatible methods to IntrinsicInst/IRBuilder

2019-12-12 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2019-12-12T16:22:15+01:00
New Revision: dbc5acf8ce8ae7b9adfa61e8133b50f2b82e4cde

URL: 
https://github.com/llvm/llvm-project/commit/dbc5acf8ce8ae7b9adfa61e8133b50f2b82e4cde
DIFF: 
https://github.com/llvm/llvm-project/commit/dbc5acf8ce8ae7b9adfa61e8133b50f2b82e4cde.diff

LOG: [Alignment][NFC] Adding Align compatible methods to IntrinsicInst/IRBuilder

Summary:
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

Reviewers: courbet

Subscribers: hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D71420

Added: 


Modified: 
clang/lib/CodeGen/CGBuilder.h
llvm/include/llvm/IR/IRBuilder.h
llvm/include/llvm/IR/IntrinsicInst.h
llvm/lib/IR/IRBuilder.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h
index 746053f43e36..107c9275431c 100644
--- a/clang/lib/CodeGen/CGBuilder.h
+++ b/clang/lib/CodeGen/CGBuilder.h
@@ -107,7 +107,7 @@ class CGBuilderTy : public CGBuilderBaseTy {
   llvm::StoreInst *CreateStore(llvm::Value *Val, Address Addr,
bool IsVolatile = false) {
 return CreateAlignedStore(Val, Addr.getPointer(),
-  Addr.getAlignment().getQuantity(), IsVolatile);
+  Addr.getAlignment().getAsAlign(), IsVolatile);
   }
 
   using CGBuilderBaseTy::CreateAlignedStore;
@@ -273,22 +273,22 @@ class CGBuilderTy : public CGBuilderBaseTy {
   using CGBuilderBaseTy::CreateMemCpy;
   llvm::CallInst *CreateMemCpy(Address Dest, Address Src, llvm::Value *Size,
bool IsVolatile = false) {
-return CreateMemCpy(Dest.getPointer(), Dest.getAlignment().getQuantity(),
-Src.getPointer(), Src.getAlignment().getQuantity(),
-Size,IsVolatile);
+return CreateMemCpy(Dest.getPointer(), Dest.getAlignment().getAsAlign(),
+Src.getPointer(), Src.getAlignment().getAsAlign(), 
Size,
+IsVolatile);
   }
   llvm::CallInst *CreateMemCpy(Address Dest, Address Src, uint64_t Size,
bool IsVolatile = false) {
-return CreateMemCpy(Dest.getPointer(), Dest.getAlignment().getQuantity(),
-Src.getPointer(), Src.getAlignment().getQuantity(),
-Size, IsVolatile);
+return CreateMemCpy(Dest.getPointer(), Dest.getAlignment().getAsAlign(),
+Src.getPointer(), Src.getAlignment().getAsAlign(), 
Size,
+IsVolatile);
   }
 
   using CGBuilderBaseTy::CreateMemMove;
   llvm::CallInst *CreateMemMove(Address Dest, Address Src, llvm::Value *Size,
 bool IsVolatile = false) {
-return CreateMemMove(Dest.getPointer(), Dest.getAlignment().getQuantity(),
- Src.getPointer(), Src.getAlignment().getQuantity(),
+return CreateMemMove(Dest.getPointer(), Dest.getAlignment().getAsAlign(),
+ Src.getPointer(), Src.getAlignment().getAsAlign(),
  Size, IsVolatile);
   }
 

diff  --git a/llvm/include/llvm/IR/IRBuilder.h 
b/llvm/include/llvm/IR/IRBuilder.h
index b15940b371ef..fdc4f5bdbf0f 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -491,28 +491,32 @@ class IRBuilderBase {
   /// If the pointers aren't i8*, they will be converted.  If a TBAA tag is
   /// specified, it will be added to the instruction. Likewise with alias.scope
   /// and noalias tags.
+  /// FIXME: Remove this function once transition to Align is over.
+  /// Use the version that takes MaybeAlign instead of this one.
   CallInst *CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src,
  unsigned SrcAlign, uint64_t Size,
  bool isVolatile = false, MDNode *TBAATag = nullptr,
  MDNode *TBAAStructTag = nullptr,
  MDNode *ScopeTag = nullptr,
  MDNode *NoAliasTag = nullptr) {
-return CreateMemCpy(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
-isVolatile, TBAATag, TBAAStructTag, ScopeTag,
-NoAliasTag);
+return CreateMemCpy(Dst, MaybeAlign(DstAlign), Src, MaybeAlign(SrcAlign),
+getInt64(Size), isVolatile, TBAATag, TBAAStructTag,
+ScopeTag, NoAliasTag);
   }
+
   CallInst *CreateMemCpy(Value *Dst, MaybeAlign DstAlign, Value *Src,
  MaybeAlign SrcAlign, uint64_t Size,
  bool isVolatile = false, MDNode *TBAATag = nullptr,
  MDNod

[clang] 0508c99 - [clang] Turn -fno-builtin flag into an IR Attribute

2019-12-12 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2019-12-12T17:21:12+01:00
New Revision: 0508c994f0b14144041f2cfd3ba9f9a80f03de08

URL: 
https://github.com/llvm/llvm-project/commit/0508c994f0b14144041f2cfd3ba9f9a80f03de08
DIFF: 
https://github.com/llvm/llvm-project/commit/0508c994f0b14144041f2cfd3ba9f9a80f03de08.diff

LOG: [clang] Turn -fno-builtin flag into an IR Attribute

Summary:
This is a follow up on https://reviews.llvm.org/D61634#1742154 to turn the 
clang driver -fno-builtin flag into an IR attribute.
I also investigated pushing the attribute earlier on (in Sema) but it looks 
like this patch is simple and will cover all function calls.

Reviewers: aaron.ballman, courbet

Subscribers: cfe-commits, tejohnson

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71193

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/test/CodeGen/libcalls-fno-builtin.c
clang/test/CodeGen/memccpy-libcall.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index d41516b7eab3..b49b194d6112 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1877,17 +1877,20 @@ void CodeGenModule::ConstructAttributeList(
 if (Fn->isNoReturn())
   FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
 
-if (const auto *NBA = TargetDecl->getAttr()) {
-  bool HasWildcard = llvm::is_contained(NBA->builtinNames(), "*");
-  if (HasWildcard)
-FuncAttrs.addAttribute("no-builtins");
-  else
-for (StringRef BuiltinName : NBA->builtinNames()) {
-  SmallString<32> AttributeName;
-  AttributeName += "no-builtin-";
-  AttributeName += BuiltinName;
-  FuncAttrs.addAttribute(AttributeName);
-}
+const auto *NBA = Fn->getAttr();
+bool HasWildcard = NBA && llvm::is_contained(NBA->builtinNames(), "*");
+if (getLangOpts().NoBuiltin || HasWildcard)
+  FuncAttrs.addAttribute("no-builtins");
+else {
+  auto AddNoBuiltinAttr = [&FuncAttrs](StringRef BuiltinName) {
+SmallString<32> AttributeName;
+AttributeName += "no-builtin-";
+AttributeName += BuiltinName;
+FuncAttrs.addAttribute(AttributeName);
+  };
+  llvm::for_each(getLangOpts().NoBuiltinFuncs, AddNoBuiltinAttr);
+  if (NBA)
+llvm::for_each(NBA->builtinNames(), AddNoBuiltinAttr);
 }
   }
 }

diff  --git a/clang/test/CodeGen/libcalls-fno-builtin.c 
b/clang/test/CodeGen/libcalls-fno-builtin.c
index 6fac6ee3390b..54fadb6cf28e 100644
--- a/clang/test/CodeGen/libcalls-fno-builtin.c
+++ b/clang/test/CodeGen/libcalls-fno-builtin.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -S -emit-llvm -fno-builtin -o - %s | FileCheck %s
+// RUN: %clang_cc1 -S -emit-llvm -fno-builtin -o - %s | FileCheck 
--check-prefixes=GLOBAL,CHECK %s
 // RUN: %clang_cc1 -S -emit-llvm -fno-builtin-ceil -fno-builtin-copysign 
-fno-builtin-cos \
 // RUN:  -fno-builtin-fabs -fno-builtin-floor -fno-builtin-strcat 
-fno-builtin-strncat \
 // RUN:  -fno-builtin-strchr -fno-builtin-strrchr -fno-builtin-strcmp 
-fno-builtin-strncmp \
@@ -6,7 +6,7 @@
 // RUN:  -fno-builtin-strpbrk -fno-builtin-strspn -fno-builtin-strtod 
-fno-builtin-strtof \
 // RUN:  -fno-builtin-strtold -fno-builtin-strtol -fno-builtin-strtoll 
-fno-builtin-strtoul \
 // RUN:  -fno-builtin-strtoull -fno-builtin-fread -fno-builtin-fwrite 
-fno-builtin-fopen \
-// RUN:  -o - %s | FileCheck %s
+// RUN:  -o - %s | FileCheck --check-prefixes=INDIVIDUAL,CHECK %s
 // RUN: %clang_cc1 -S -O3 -fno-builtin -o - %s | FileCheck --check-prefix=ASM 
%s
 // RUN: %clang_cc1 -S -O3 -fno-builtin-ceil -o - %s | FileCheck 
--check-prefix=ASM-INDIV %s
 
@@ -56,108 +56,109 @@ double t1(double x) { return ceil(x); }
 
 double t2(double x, double y) { return copysign(x,y); }
 // CHECK-LABEL: t2
-// CHECK: call{{.*}}@copysign{{.*}} [[ATTR]]
+// CHECK: call{{.*}}@copysign{{.*}} #2
 
 double t3(double x) { return cos(x); }
 // CHECK-LABEL: t3
-// CHECK: call{{.*}}@cos{{.*}} [[ATTR]]
+// CHECK: call{{.*}}@cos{{.*}} #2
 
 double t4(double x) { return fabs(x); }
 // CHECK-LABEL: t4
-// CHECK: call{{.*}}@fabs{{.*}} [[ATTR]]
+// CHECK: call{{.*}}@fabs{{.*}} #2
 
 double t5(double x) { return floor(x); }
 // CHECK-LABEL: t5
-// CHECK: call{{.*}}@floor{{.*}} [[ATTR]]
+// CHECK: call{{.*}}@floor{{.*}} #2
 
 char *t6(char *x) { return strcat(x, ""); }
 // CHECK-LABEL: t6
-// CHECK: call{{.*}}@strcat{{.*}} [[ATTR]]
+// CHECK: call{{.*}}@strcat{{.*}} #2
 
 char *t7(char *x) { return strncat(x, "", 1); }
 // CHECK-LABEL: t7
-// CHECK: call{{.*}}@strncat{{.*}} [[ATTR]]
+// CHECK: call{{.*}}@strncat{{.*}} #2
 
 char *t8(void) { return strchr("hello, world", 'w'); }
 // CHECK-LABEL: t8
-// CHECK: call{{.*}}@strchr{{.*}} [[ATTR]]
+// CHECK: call{{.*}}@strchr{{.*}} #2
 
 char *t9(void) { return

[clang] d65bbf8 - [clang] Add support for __builtin_memcpy_inline

2020-02-07 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2020-02-07T23:55:26+01:00
New Revision: d65bbf81f8be3ff806b86776cf95b001a4cf43ad

URL: 
https://github.com/llvm/llvm-project/commit/d65bbf81f8be3ff806b86776cf95b001a4cf43ad
DIFF: 
https://github.com/llvm/llvm-project/commit/d65bbf81f8be3ff806b86776cf95b001a4cf43ad.diff

LOG: [clang] Add support for __builtin_memcpy_inline

Summary: This is a follow up on D61634 and the last step to implement 
http://lists.llvm.org/pipermail/llvm-dev/2019-April/131973.html

Reviewers: efriedma, courbet, tejohnson

Subscribers: hiraditya, cfe-commits, llvm-commits, jdoerfert, t.p.northover

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D73543

Added: 
clang/test/CodeGen/builtins-memcpy-inline.c
clang/test/Sema/builtins-memcpy-inline.c

Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/Builtins.def
clang/lib/CodeGen/CGBuilder.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Sema/SemaChecking.cpp
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/IR/IRBuilder.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index f1df9dd93f93..9af49e3a60d7 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2260,6 +2260,23 @@ is disallowed in general).
 Support for constant expression evaluation for the above builtins be detected
 with ``__has_feature(cxx_constexpr_string_builtins)``.
 
+Memory builtins
+---
+
+ * ``__builtin_memcpy_inline``
+
+.. code-block:: c
+
+  void __builtin_memcpy_inline(void *dst, const void *src, size_t size);
+
+``__builtin_memcpy_inline(dst, src, size)`` is identical to
+``__builtin_memcpy(dst, src, size)`` except that the generated code is
+guaranteed not to call any external functions. See [LLVM IR 
‘llvm.memcpy.inline’
+Intrinsic](https://llvm.org/docs/LangRef.html#llvm-memcpy-inline-intrinsic) for
+more information.
+
+Note that the `size` argument must be a compile time constant.
+
 Atomic Min/Max builtins with memory ordering
 
 

diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 1a6c85ce2dd3..9a68f72da6d9 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -480,6 +480,7 @@ BUILTIN(__builtin_fprintf, "iP*cC*.", "Fp:1:")
 BUILTIN(__builtin_memchr, "v*vC*iz", "nF")
 BUILTIN(__builtin_memcmp, "ivC*vC*z", "nF")
 BUILTIN(__builtin_memcpy, "v*v*vC*z", "nF")
+BUILTIN(__builtin_memcpy_inline, "vv*vC*Iz", "nt")
 BUILTIN(__builtin_memmove, "v*v*vC*z", "nF")
 BUILTIN(__builtin_mempcpy, "v*v*vC*z", "nF")
 BUILTIN(__builtin_memset, "v*v*iz", "nF")

diff  --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h
index e736e83a8c66..7687f7990d99 100644
--- a/clang/lib/CodeGen/CGBuilder.h
+++ b/clang/lib/CodeGen/CGBuilder.h
@@ -280,6 +280,13 @@ class CGBuilderTy : public CGBuilderBaseTy {
 IsVolatile);
   }
 
+  using CGBuilderBaseTy::CreateMemCpyInline;
+  llvm::CallInst *CreateMemCpyInline(Address Dest, Address Src, uint64_t Size) 
{
+return CreateMemCpyInline(
+Dest.getPointer(), Dest.getAlignment().getAsAlign(), Src.getPointer(),
+Src.getAlignment().getAsAlign(), getInt64(Size));
+  }
+
   using CGBuilderBaseTy::CreateMemMove;
   llvm::CallInst *CreateMemMove(Address Dest, Address Src, llvm::Value *Size,
 bool IsVolatile = false) {

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7e0c53126914..509400bfc574 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -2518,6 +2518,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   return RValue::get(Dest.getPointer());
   }
 
+  case Builtin::BI__builtin_memcpy_inline: {
+Address Dest = EmitPointerWithAlignment(E->getArg(0));
+Address Src = EmitPointerWithAlignment(E->getArg(1));
+uint64_t Size =
+E->getArg(2)->EvaluateKnownConstInt(getContext()).getZExtValue();
+EmitNonNullArgCheck(RValue::get(Dest.getPointer()), 
E->getArg(0)->getType(),
+E->getArg(0)->getExprLoc(), FD, 0);
+EmitNonNullArgCheck(RValue::get(Src.getPointer()), E->getArg(1)->getType(),
+E->getArg(1)->getExprLoc(), FD, 1);
+Builder.CreateMemCpyInline(Dest, Src, Size);
+return RValue::get(nullptr);
+  }
+
   case Builtin::BI__builtin_char_memchr:
 BuiltinID = Builtin::BI__builtin_memchr;
 break;

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index ab63120bf842..a06a82331c9b 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -1376,6 +1376,9 @@ CheckBuiltinTargetSupport(Sema &S, unsigned BuiltinID, 
CallExpr *TheCall,
   return true;
 }

[clang] bc8a1ab - [Alignment][NFC] Use Align with CreateMaskedLoad

2020-01-21 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2020-01-21T14:13:22+01:00
New Revision: bc8a1ab26fba5d5635467b9d0fd7ad9a0fd5bc6e

URL: 
https://github.com/llvm/llvm-project/commit/bc8a1ab26fba5d5635467b9d0fd7ad9a0fd5bc6e
DIFF: 
https://github.com/llvm/llvm-project/commit/bc8a1ab26fba5d5635467b9d0fd7ad9a0fd5bc6e.diff

LOG: [Alignment][NFC] Use Align with CreateMaskedLoad

Summary:
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

Reviewers: courbet

Subscribers: hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D73087

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
llvm/include/llvm/Analysis/VectorUtils.h
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/IR/IRBuilder.cpp
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 9986ea4cb94c..8d00d3d64f5c 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9727,8 +9727,8 @@ static Value *EmitX86MaskedStore(CodeGenFunction &CGF,
   return CGF.Builder.CreateMaskedStore(Ops[1], Ptr, Align, MaskVec);
 }
 
-static Value *EmitX86MaskedLoad(CodeGenFunction &CGF,
-ArrayRef Ops, unsigned Align) {
+static Value *EmitX86MaskedLoad(CodeGenFunction &CGF, ArrayRef Ops,
+Align Alignment) {
   // Cast the pointer to right type.
   Value *Ptr = CGF.Builder.CreateBitCast(Ops[0],

llvm::PointerType::getUnqual(Ops[1]->getType()));
@@ -9736,7 +9736,7 @@ static Value *EmitX86MaskedLoad(CodeGenFunction &CGF,
   Value *MaskVec = getMaskVecValue(CGF, Ops[2],
Ops[1]->getType()->getVectorNumElements());
 
-  return CGF.Builder.CreateMaskedLoad(Ptr, Align, MaskVec, Ops[1]);
+  return CGF.Builder.CreateMaskedLoad(Ptr, Alignment, MaskVec, Ops[1]);
 }
 
 static Value *EmitX86ExpandLoad(CodeGenFunction &CGF,
@@ -10731,11 +10731,11 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   case X86::BI__builtin_ia32_loaddqudi128_mask:
   case X86::BI__builtin_ia32_loaddqudi256_mask:
   case X86::BI__builtin_ia32_loaddqudi512_mask:
-return EmitX86MaskedLoad(*this, Ops, 1);
+return EmitX86MaskedLoad(*this, Ops, Align::None());
 
   case X86::BI__builtin_ia32_loadss128_mask:
   case X86::BI__builtin_ia32_loadsd128_mask:
-return EmitX86MaskedLoad(*this, Ops, 1);
+return EmitX86MaskedLoad(*this, Ops, Align::None());
 
   case X86::BI__builtin_ia32_loadaps128_mask:
   case X86::BI__builtin_ia32_loadaps256_mask:
@@ -10748,11 +10748,10 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   case X86::BI__builtin_ia32_movdqa32load512_mask:
   case X86::BI__builtin_ia32_movdqa64load128_mask:
   case X86::BI__builtin_ia32_movdqa64load256_mask:
-  case X86::BI__builtin_ia32_movdqa64load512_mask: {
-unsigned Align =
-  getContext().getTypeAlignInChars(E->getArg(1)->getType()).getQuantity();
-return EmitX86MaskedLoad(*this, Ops, Align);
-  }
+  case X86::BI__builtin_ia32_movdqa64load512_mask:
+return EmitX86MaskedLoad(
+*this, Ops,
+
getContext().getTypeAlignInChars(E->getArg(1)->getType()).getAsAlign());
 
   case X86::BI__builtin_ia32_expandloaddf128_mask:
   case X86::BI__builtin_ia32_expandloaddf256_mask:

diff  --git a/llvm/include/llvm/Analysis/VectorUtils.h 
b/llvm/include/llvm/Analysis/VectorUtils.h
index dd42b4f5be93..8b465ca2983d 100644
--- a/llvm/include/llvm/Analysis/VectorUtils.h
+++ b/llvm/include/llvm/Analysis/VectorUtils.h
@@ -509,6 +509,7 @@ template  class InterleaveGroup {
   bool isReverse() const { return Reverse; }
   uint32_t getFactor() const { return Factor; }
   uint32_t getAlignment() const { return Alignment.value(); }
+  Align getAlign() const { return Alignment; }
   uint32_t getNumMembers() const { return Members.size(); }
 
   /// Try to insert a new member \p Instr with index \p Index and

diff  --git a/llvm/include/llvm/IR/IRBuilder.h 
b/llvm/include/llvm/IR/IRBuilder.h
index 6f6d6db31726..9341810c7b3b 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -727,7 +727,14 @@ class IRBuilderBase {
   CallInst *CreateInvariantStart(Value *Ptr, ConstantInt *Size = nullptr);
 
   /// Create a call to Masked Load intrinsic
-  CallInst *CreateMaskedLoad(Value *Ptr, unsigned Align, Value *Mask,
+  LLVM_ATTRIBUTE_DEPRECATED(
+  CallInst *CreateMaskedLoad(Value *Ptr, unsigned Alignment, Value *Mask,
+ Value *

[clang] 0957233 - [Alignment][NFC] Use Align with CreateMaskedStore

2020-01-22 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2020-01-22T11:04:39+01:00
New Revision: 0957233320eb0096bbb7665e0762a13bad1e7cb8

URL: 
https://github.com/llvm/llvm-project/commit/0957233320eb0096bbb7665e0762a13bad1e7cb8
DIFF: 
https://github.com/llvm/llvm-project/commit/0957233320eb0096bbb7665e0762a13bad1e7cb8.diff

LOG: [Alignment][NFC] Use Align with CreateMaskedStore

Summary:
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

Reviewers: courbet

Subscribers: hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D73106

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
llvm/include/llvm/IR/Constants.h
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/CodeGen/ScalarizeMaskedMemIntrin.cpp
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/IR/IRBuilder.cpp
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 29eebbb403ea..86a3f1e0d237 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9714,9 +9714,8 @@ static Value *getMaskVecValue(CodeGenFunction &CGF, Value 
*Mask,
   return MaskVec;
 }
 
-static Value *EmitX86MaskedStore(CodeGenFunction &CGF,
- ArrayRef Ops,
- unsigned Align) {
+static Value *EmitX86MaskedStore(CodeGenFunction &CGF, ArrayRef Ops,
+ Align Alignment) {
   // Cast the pointer to right type.
   Value *Ptr = CGF.Builder.CreateBitCast(Ops[0],

llvm::PointerType::getUnqual(Ops[1]->getType()));
@@ -9724,7 +9723,7 @@ static Value *EmitX86MaskedStore(CodeGenFunction &CGF,
   Value *MaskVec = getMaskVecValue(CGF, Ops[2],
Ops[1]->getType()->getVectorNumElements());
 
-  return CGF.Builder.CreateMaskedStore(Ops[1], Ptr, Align, MaskVec);
+  return CGF.Builder.CreateMaskedStore(Ops[1], Ptr, Alignment, MaskVec);
 }
 
 static Value *EmitX86MaskedLoad(CodeGenFunction &CGF, ArrayRef Ops,
@@ -10592,12 +10591,12 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   case X86::BI__builtin_ia32_storedquqi512_mask:
   case X86::BI__builtin_ia32_storeupd512_mask:
   case X86::BI__builtin_ia32_storeups512_mask:
-return EmitX86MaskedStore(*this, Ops, 1);
+return EmitX86MaskedStore(*this, Ops, Align::None());
 
   case X86::BI__builtin_ia32_storess128_mask:
-  case X86::BI__builtin_ia32_storesd128_mask: {
-return EmitX86MaskedStore(*this, Ops, 1);
-  }
+  case X86::BI__builtin_ia32_storesd128_mask:
+return EmitX86MaskedStore(*this, Ops, Align::None());
+
   case X86::BI__builtin_ia32_vpopcntb_128:
   case X86::BI__builtin_ia32_vpopcntd_128:
   case X86::BI__builtin_ia32_vpopcntq_128:
@@ -10708,11 +10707,11 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   case X86::BI__builtin_ia32_movdqa32store512_mask:
   case X86::BI__builtin_ia32_movdqa64store512_mask:
   case X86::BI__builtin_ia32_storeaps512_mask:
-  case X86::BI__builtin_ia32_storeapd512_mask: {
-unsigned Align =
-  getContext().getTypeAlignInChars(E->getArg(1)->getType()).getQuantity();
-return EmitX86MaskedStore(*this, Ops, Align);
-  }
+  case X86::BI__builtin_ia32_storeapd512_mask:
+return EmitX86MaskedStore(
+*this, Ops,
+
getContext().getTypeAlignInChars(E->getArg(1)->getType()).getAsAlign());
+
   case X86::BI__builtin_ia32_loadups128_mask:
   case X86::BI__builtin_ia32_loadups256_mask:
   case X86::BI__builtin_ia32_loadups512_mask:

diff  --git a/llvm/include/llvm/IR/Constants.h 
b/llvm/include/llvm/IR/Constants.h
index 262ab439df65..9b3c1e723a10 100644
--- a/llvm/include/llvm/IR/Constants.h
+++ b/llvm/include/llvm/IR/Constants.h
@@ -157,6 +157,10 @@ class ConstantInt final : public ConstantData {
 return Val.getSExtValue();
   }
 
+  /// Return the constant as an llvm::Align. Note that this method can assert 
if
+  /// the value does not fit in 64 bits or is not a power of two.
+  inline Align getAlignValue() const { return Align(getZExtValue()); }
+
   /// A helper method that can be used to determine if the constant contained
   /// within is equal to a constant.  This only works for very small values,
   /// because this is all that can be represented with all types.

diff  --git a/llvm/include/llvm/IR/IRBuilder.h 
b/llvm/include/llvm/IR/IRBuilder.h
index b02945f98101..4d242ae64067 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -752,13 +752,21 @@ class IRBuilderBase {
  

[clang] 59f9522 - [Alignment][NFC] Use Align with CreateAlignedStore

2020-01-23 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2020-01-23T17:34:32+01:00
New Revision: 59f95222d4c5e997342b0514984823a99a16d44b

URL: 
https://github.com/llvm/llvm-project/commit/59f95222d4c5e997342b0514984823a99a16d44b
DIFF: 
https://github.com/llvm/llvm-project/commit/59f95222d4c5e997342b0514984823a99a16d44b.diff

LOG: [Alignment][NFC] Use Align with CreateAlignedStore

Summary:
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

Reviewers: courbet, bollu

Subscribers: arsenm, jvesely, nhaehnle, hiraditya, kerbowa, cfe-commits, 
llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D73274

Added: 


Modified: 
clang/lib/CodeGen/CGBlocks.cpp
clang/lib/CodeGen/CGBuilder.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGGPUBuiltin.cpp
clang/lib/CodeGen/CGObjCGNU.cpp
clang/lib/CodeGen/TargetInfo.cpp
llvm/include/llvm/IR/DataLayout.h
llvm/include/llvm/IR/GlobalObject.h
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/CodeGen/ScalarizeMaskedMemIntrin.cpp
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/IR/DataLayout.cpp
llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp
llvm/lib/Target/X86/X86InterleavedAccess.cpp
llvm/lib/Transforms/IPO/LowerTypeTests.cpp
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/lib/Transforms/Scalar/Scalarizer.cpp
llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
polly/lib/CodeGen/BlockGenerators.cpp
polly/lib/CodeGen/LoopGeneratorsKMP.cpp
polly/lib/CodeGen/RuntimeDebugBuilder.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 11f54d1f7fb2..33fad77eb4da 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -1449,7 +1449,8 @@ static llvm::Constant *buildGlobalBlock(CodeGenModule 
&CGM,
 llvm::IRBuilder<> b(llvm::BasicBlock::Create(CGM.getLLVMContext(), "entry",
   Init));
 b.CreateAlignedStore(CGM.getNSConcreteGlobalBlock(),
-b.CreateStructGEP(literal, 0), CGM.getPointerAlign().getQuantity());
+ b.CreateStructGEP(literal, 0),
+ CGM.getPointerAlign().getAsAlign());
 b.CreateRetVoid();
 // We can't use the normal LLVM global initialisation array, because we
 // need to specify that this runs early in library initialisation.

diff  --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h
index 107c9275431c..049e1d4b7552 100644
--- a/clang/lib/CodeGen/CGBuilder.h
+++ b/clang/lib/CodeGen/CGBuilder.h
@@ -113,7 +113,7 @@ class CGBuilderTy : public CGBuilderBaseTy {
   using CGBuilderBaseTy::CreateAlignedStore;
   llvm::StoreInst *CreateAlignedStore(llvm::Value *Val, llvm::Value *Addr,
   CharUnits Align, bool IsVolatile = 
false) {
-return CreateAlignedStore(Val, Addr, Align.getQuantity(), IsVolatile);
+return CreateAlignedStore(Val, Addr, Align.getAsAlign(), IsVolatile);
   }
 
   // FIXME: these "default-aligned" APIs should be removed,

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 86a3f1e0d237..04511e892adf 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3930,7 +3930,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 auto *V =
 Builder.CreateZExtOrTrunc(EmitScalarExpr(E->getArg(I)), SizeTy);
 Builder.CreateAlignedStore(
-V, GEP, CGM.getDataLayout().getPrefTypeAlignment(SizeTy));
+V, GEP, CGM.getDataLayout().getPrefTypeAlign(SizeTy));
   }
   return std::tie(ElemPtr, TmpSize, TmpPtr);
 };

diff  --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp 
b/clang/lib/CodeGen/CGGPUBuiltin.cpp
index bccce7dd7ff4..f860623e2bc3 100644
--- a/clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ b/clang/lib/CodeGen/CGGPUBuiltin.cpp
@@ -111,7 +111,7 @@ CodeGenFunction::EmitNVPTXDevicePrintfCallExpr(const 
CallExpr *E,
 for (unsigned I = 1, NumArgs = Args.size(); I < NumArgs; ++I) {
   llvm::Value *P = Builder.CreateStructGEP(AllocaTy, Alloca, I - 1);
   llvm::Value *Arg = Args[I].getRValue(*this).getScalarVal();
-  Builder.CreateAlignedStore(Arg, P, 
DL.getPrefTypeAlignment(Arg->getType()));
+  Builder.CreateAlignedStore(Arg, P, DL.getPrefTypeAlign(Arg->getType()));
 

[clang] 07c9d53 - [Alignment][NFC] Use Align with CreateAlignedLoad

2020-01-27 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2020-01-27T10:58:36+01:00
New Revision: 07c9d5326648802560adbc1b1b61316c7d3c406d

URL: 
https://github.com/llvm/llvm-project/commit/07c9d5326648802560adbc1b1b61316c7d3c406d
DIFF: 
https://github.com/llvm/llvm-project/commit/07c9d5326648802560adbc1b1b61316c7d3c406d.diff

LOG: [Alignment][NFC] Use Align with CreateAlignedLoad

Summary:
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

Reviewers: courbet, bollu

Subscribers: hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D73449

Added: 


Modified: 
clang/lib/CodeGen/CGBuilder.h
clang/lib/CodeGen/CGCXX.cpp
clang/lib/CodeGen/CodeGenFunction.h
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
polly/lib/CodeGen/BlockGenerators.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h
index 049e1d4b7552..e736e83a8c66 100644
--- a/clang/lib/CodeGen/CGBuilder.h
+++ b/clang/lib/CodeGen/CGBuilder.h
@@ -68,38 +68,34 @@ class CGBuilderTy : public CGBuilderBaseTy {
   // take an alignment.
   llvm::LoadInst *CreateLoad(Address Addr, const llvm::Twine &Name = "") {
 return CreateAlignedLoad(Addr.getPointer(),
- Addr.getAlignment().getQuantity(),
- Name);
+ Addr.getAlignment().getAsAlign(), Name);
   }
   llvm::LoadInst *CreateLoad(Address Addr, const char *Name) {
 // This overload is required to prevent string literals from
 // ending up in the IsVolatile overload.
 return CreateAlignedLoad(Addr.getPointer(),
- Addr.getAlignment().getQuantity(),
- Name);
+ Addr.getAlignment().getAsAlign(), Name);
   }
   llvm::LoadInst *CreateLoad(Address Addr, bool IsVolatile,
  const llvm::Twine &Name = "") {
-return CreateAlignedLoad(Addr.getPointer(),
- Addr.getAlignment().getQuantity(),
- IsVolatile,
- Name);
+return CreateAlignedLoad(
+Addr.getPointer(), Addr.getAlignment().getAsAlign(), IsVolatile, Name);
   }
 
   using CGBuilderBaseTy::CreateAlignedLoad;
   llvm::LoadInst *CreateAlignedLoad(llvm::Value *Addr, CharUnits Align,
 const llvm::Twine &Name = "") {
-return CreateAlignedLoad(Addr, Align.getQuantity(), Name);
+return CreateAlignedLoad(Addr, Align.getAsAlign(), Name);
   }
   llvm::LoadInst *CreateAlignedLoad(llvm::Value *Addr, CharUnits Align,
 const char *Name) {
-return CreateAlignedLoad(Addr, Align.getQuantity(), Name);
+return CreateAlignedLoad(Addr, Align.getAsAlign(), Name);
   }
   llvm::LoadInst *CreateAlignedLoad(llvm::Type *Ty, llvm::Value *Addr,
 CharUnits Align,
 const llvm::Twine &Name = "") {
 assert(Addr->getType()->getPointerElementType() == Ty);
-return CreateAlignedLoad(Addr, Align.getQuantity(), Name);
+return CreateAlignedLoad(Addr, Align.getAsAlign(), Name);
   }
 
   // Note that we intentionally hide the CreateStore APIs that don't

diff  --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp
index 1928e0df3809..a4bd2c6d5da0 100644
--- a/clang/lib/CodeGen/CGCXX.cpp
+++ b/clang/lib/CodeGen/CGCXX.cpp
@@ -263,8 +263,8 @@ static CGCallee BuildAppleKextVirtualCall(CodeGenFunction 
&CGF,
  AddressPoint.AddressPointIndex;
   llvm::Value *VFuncPtr =
 CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfnkxt");
-  llvm::Value *VFunc =
-CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.PointerAlignInBytes);
+  llvm::Value *VFunc = CGF.Builder.CreateAlignedLoad(
+  VFuncPtr, llvm::Align(CGF.PointerAlignInBytes));
   CGCallee Callee(GD, VFunc);
   return Callee;
 }

diff  --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index e4f60330bcc5..f48d8a4cc366 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4414,7 +4414,7 @@ inline llvm::Value 
*DominatingLLVMValue::restore(CodeGenFunction &CGF,
 
   // Otherwise, it should be an alloca instruction, as set up in save().
   auto alloca = cast(value.getPointer());
-  return CGF.Builder.CreateAlignedLoad(alloca, alloca->getAlignment());
+  return CGF.Builder.CreateAlignedLoad(alloca, alloca->getAlign());
 }
 
 }  // end namespace CodeGen

diff  --git a/llvm/include/llvm/IR/IRBuilder.h 
b/llvm/include/llvm/IR/IRBuilder.h
index 7d75cd68bea0..5a290464739e 100644
---