r332350 - [clang] Update uses of DEBUG macro to LLVM_DEBUG.

2018-05-15 Thread Nicola Zaghen via cfe-commits
Author: nzaghen
Date: Tue May 15 06:30:56 2018
New Revision: 332350

URL: http://llvm.org/viewvc/llvm-project?rev=332350&view=rev
Log:
[clang] Update uses of DEBUG macro to LLVM_DEBUG.

The DEBUG() macro is very generic so it might clash with other projects.
The renaming was done as follows:
- git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g'
- git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 
-style LLVM

Explicitly avoided changing the strings in the clang-format tests.

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


Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Analysis/BodyFarm.cpp
cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/SortJavaScriptImports.cpp
cfe/trunk/lib/Format/TokenAnalyzer.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/lib/Format/UsingDeclarationsSorter.cpp
cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
cfe/trunk/lib/Tooling/Tooling.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
cfe/trunk/unittests/Format/FormatTestComments.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
cfe/trunk/unittests/Format/FormatTestJava.cpp
cfe/trunk/unittests/Format/FormatTestObjC.cpp
cfe/trunk/unittests/Format/FormatTestProto.cpp
cfe/trunk/unittests/Format/FormatTestRawStrings.cpp
cfe/trunk/unittests/Format/FormatTestSelective.cpp
cfe/trunk/unittests/Format/FormatTestTextProto.cpp
cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp
cfe/trunk/unittests/Format/UsingDeclarationsSorterTest.cpp
cfe/trunk/unittests/libclang/LibclangTest.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=332350&r1=332349&r2=332350&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue May 15 06:30:56 2018
@@ -6961,8 +6961,8 @@ bool ArrayExprEvaluator::VisitInitListEx
   if (NumEltsToInit != NumElts && MaybeElementDependentArrayFiller(FillerExpr))
 NumEltsToInit = NumElts;
 
-  DEBUG(llvm::dbgs() << "The number of elements to initialize: " <<
-NumEltsToInit << ".\n");
+  LLVM_DEBUG(llvm::dbgs() << "The number of elements to initialize: "
+  << NumEltsToInit << ".\n");
 
   Result = APValue(APValue::UninitArray(), NumEltsToInit, NumElts);
 

Modified: cfe/trunk/lib/Analysis/BodyFarm.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BodyFarm.cpp?rev=332350&r1=332349&r2=332350&view=diff
==
--- cfe/trunk/lib/Analysis/BodyFarm.cpp (original)
+++ cfe/trunk/lib/Analysis/BodyFarm.cpp Tue May 15 06:30:56 2018
@@ -314,7 +314,7 @@ static CallExpr *create_call_once_lambda
 /// }
 /// \endcode
 static Stmt *create_call_once(ASTContext &C, const FunctionDecl *D) {
-  DEBUG(llvm::dbgs() << "Generating body for call_once\n");
+  LLVM_DEBUG(llvm::dbgs() << "Generating body for call_once\n");
 
   // We need at least two parameters.
   if (D->param_size() < 2)
@@ -342,9 +342,9 @@ static Stmt *create_call_once(ASTContext
   auto *FlagRecordDecl = 
dyn_cast_or_null(FlagType->getAsTagDecl());
 
   if (!FlagRecordDecl) {
-DEBUG(llvm::dbgs() << "Flag field is not a record: "
-   << "unknown std::call_once implementation, "
-   << "ignoring the call.\n");
+LLVM_DEBUG(llvm::dbgs() << "Flag field is not a record: "
+<< "unknown std::call_once implementation, "
+<< "ignoring the call.\n");
 return nullptr;
   }
 
@@ -359,16 +359,17 @@ static Stmt *create_call_once(ASTContext
   }
 
   if (!FlagFieldDecl) {
-DEBUG(llvm::dbgs() << "No field _M_once or __state_ found on "
-   << "std::once_flag struct: unknown std::call_once "
-   << "implementation, ignoring the call.");
+LLVM_DEBUG(llvm::dbgs() << "No field _M_once or __state_ found on "
+<< "std::once_flag struct: unknown std::call_once "
+<< "implementation, ignoring the call.");
 return nullptr;
   }
 
   bool isLambdaCall = CallbackRecordDecl && CallbackRecordDecl->isLambda();
   if (CallbackRecordDecl && !isLambdaCall) {
-DEBUG(llvm::dbgs() << "Not supported: synthesizing body for functors when "
-   << "body farming std::call_once, ignoring the call.");
+LLVM_DEBUG(llvm::dbgs()
+   << "Not supported: synthesizing body for functors when "
+  

[clang-tools-extra] r332371 - [clang-tools-extra] Update uses of DEBUG macro to LLVM_DEBUG.

2018-05-15 Thread Nicola Zaghen via cfe-commits
Author: nzaghen
Date: Tue May 15 09:37:45 2018
New Revision: 332371

URL: http://llvm.org/viewvc/llvm-project?rev=332371&view=rev
Log:
[clang-tools-extra] Update uses of DEBUG macro to LLVM_DEBUG.

The DEBUG() macro is very generic so it might clash with other projects.
The renaming was done as follows:
- git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g'
- git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 
-style LLVM

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


Modified:
clang-tools-extra/trunk/clang-move/ClangMove.cpp
clang-tools-extra/trunk/clang-move/HelperDeclRefGraph.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.cpp
clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp

Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=332371&r1=332370&r2=332371&view=diff
==
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original)
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Tue May 15 09:37:45 2018
@@ -680,8 +680,8 @@ void ClangMoveTool::run(const ast_matche
  Result.Nodes.getNodeAs("helper_decls")) {
 MovedDecls.push_back(ND);
 HelperDeclarations.push_back(ND);
-DEBUG(llvm::dbgs() << "Add helper : "
-   << ND->getNameAsString() << " (" << ND << ")\n");
+LLVM_DEBUG(llvm::dbgs() << "Add helper : " << ND->getNameAsString() << " ("
+<< ND << ")\n");
   } else if (const auto *UD =
  Result.Nodes.getNodeAs("using_decl")) {
 MovedDecls.push_back(UD);
@@ -741,12 +741,12 @@ void ClangMoveTool::removeDeclsInOldFile
 // We remove the helper declarations which are not used in the old.cc after
 // moving the given declarations.
 for (const auto *D : HelperDeclarations) {
-  DEBUG(llvm::dbgs() << "Check helper is used: "
- << D->getNameAsString() << " (" << D << ")\n");
+  LLVM_DEBUG(llvm::dbgs() << "Check helper is used: "
+  << D->getNameAsString() << " (" << D << ")\n");
   if (!UsedDecls.count(HelperDeclRGBuilder::getOutmostClassOrFunDecl(
   D->getCanonicalDecl( {
-DEBUG(llvm::dbgs() << "Helper removed in old.cc: "
-   << D->getNameAsString() << " (" << D << ")\n");
+LLVM_DEBUG(llvm::dbgs() << "Helper removed in old.cc: "
+<< D->getNameAsString() << " (" << D << ")\n");
 RemovedDecls.push_back(D);
   }
 }
@@ -826,8 +826,8 @@ void ClangMoveTool::moveDeclsToNewFiles(
 D->getCanonicalDecl(
   continue;
 
-DEBUG(llvm::dbgs() << "Helper used in new.cc: " << D->getNameAsString()
-   << " " << D << "\n");
+LLVM_DEBUG(llvm::dbgs() << "Helper used in new.cc: " << 
D->getNameAsString()
+<< " " << D << "\n");
 ActualNewCCDecls.push_back(D);
   }
 
@@ -937,7 +937,7 @@ void ClangMoveTool::onEndOfTranslationUn
 moveAll(SM, Context->Spec.OldCC, Context->Spec.NewCC);
 return;
   }
-  DEBUG(RGBuilder.getGraph()->dump());
+  LLVM_DEBUG(RGBuilder.getGraph()->dump());
   moveDeclsToNewFiles();
   removeDeclsInOldFiles();
 }

Modified: clang-tools-extra/trunk/clang-move/HelperDeclRefGraph.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/HelperDeclRefGraph.cpp?rev=332371&r1=332370&r2=332371&view=diff
==
--- clang-tools-extra/trunk/clang-move/HelperDeclRefGraph.cpp (original)
+++ clang-tools-extra/trunk/clang-move/HelperDeclRefGraph.cpp Tue May 15 
09:37:45 2018
@@ -116,9 +116,9 @@ void HelperDeclRGBuilder::run(
   if (const auto *FuncRef = Result.Nodes.getNodeAs("func_ref")) {
 const auto *DC = Result.Nodes.getNodeAs("dc");
 assert(DC);
-DEBUG(llvm::dbgs() << "Find helper function usage: "
-   << FuncRef->getDecl()->getNameAsString() << " ("
-   << FuncRef->getDecl() << ")\n");
+LLVM_DEBUG(llvm::dbgs() << "Find helper function usage: "
+<< FuncRef->getDecl()->getNameAsString() << " ("
+<< FuncRef->getDecl() << ")\n");
 RG->addEdge(
 getOutmostClassOrFunDecl(DC->getCanonicalDecl()),
 getOutmostClassOrFunDecl(FuncRef->getDecl()->getCanonicalDecl()));
@@ -126,9 +126,9 @@ void HelperDeclRGBuilder::run(
  Result.Nodes.getNodeAs("used_class")) {
 const auto *DC = Result.Nodes.getNodeAs("dc");
 assert(DC);
-DEBUG(llvm::dbgs() << "Find helper class usage: "
-   << UsedClass->getNameAsString() << "

[clang-tools-extra] r333083 - Replace last DEBUG occurrence with LLVM_DEBUG.

2018-05-23 Thread Nicola Zaghen via cfe-commits
Author: nzaghen
Date: Wed May 23 06:57:48 2018
New Revision: 333083

URL: http://llvm.org/viewvc/llvm-project?rev=333083&view=rev
Log:
Replace last DEBUG occurrence with LLVM_DEBUG.

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=333083&r1=333082&r2=333083&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Wed May 23 06:57:48 2018
@@ -1004,11 +1004,11 @@ private:
 Scores.symbolScore =
 Scores.filterScore ? Scores.finalScore / Scores.filterScore : 
QualScore;
 
-DEBUG(llvm::dbgs() << "CodeComplete: " << C.Name
-   << (IndexResult ? " (index)" : "")
-   << (SemaResult ? " (sema)" : "") << " = "
-   << Scores.finalScore << "\n"
-   << Quality << Relevance << "\n");
+LLVM_DEBUG(llvm::dbgs()
+   << "CodeComplete: " << C.Name << (IndexResult ? " (index)" : "")
+   << (SemaResult ? " (sema)" : "") << " = " << Scores.finalScore
+   << "\n" 
+   << Quality << Relevance << "\n");
 
 NSema += bool(SemaResult);
 NIndex += bool(IndexResult);


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


[clang] 5f62087 - [DataLayout] Fix occurrences that size and range of pointers are assumed to be the same.

2019-12-12 Thread Nicola Zaghen via cfe-commits

Author: Nicola Zaghen
Date: 2019-12-12T10:07:01Z
New Revision: 5f6208778ff92567c57d7c1e2e740c284d7e69a5

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

LOG: [DataLayout] Fix occurrences that size and range of pointers are assumed 
to be the same.

GEP index size can be specified in the DataLayout, introduced in D42123. 
However, there were still places
in which getIndexSizeInBits was used interchangeably with getPointerSizeInBits. 
This notably caused issues
with Instcombine's visitPtrToInt; but the unit tests was incorrect, so this 
remained undiscovered.

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

Patch by Joseph Faulls!

Added: 
llvm/test/Transforms/InstCombine/builtin-object-size-custom-dl.ll
llvm/test/Transforms/InstCombine/stdio-custom-dl.ll

Modified: 
clang/lib/CodeGen/CGExprScalar.cpp
llvm/include/llvm/Analysis/PtrUseVisitor.h
llvm/include/llvm/Analysis/Utils/Local.h
llvm/lib/Analysis/ConstantFolding.cpp
llvm/lib/Analysis/InlineCost.cpp
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/lib/Analysis/Loads.cpp
llvm/lib/Analysis/MemoryBuiltins.cpp
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/lib/Analysis/ScalarEvolutionExpander.cpp
llvm/lib/Analysis/ValueTracking.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/lib/IR/DataLayout.cpp
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
llvm/lib/Transforms/Utils/Local.cpp
llvm/test/Transforms/InstCombine/gep-custom-dl.ll
llvm/test/Transforms/InstCombine/icmp-custom-dl.ll
llvm/test/Transforms/PhaseOrdering/scev-custom-dl.ll
llvm/test/Transforms/SimplifyCFG/switch_create-custom-dl.ll

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index b1dcbc51f58e..b8846162508e 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -3264,10 +3264,10 @@ static Value *emitPointerArithmetic(CodeGenFunction 
&CGF,
expr->getRHS()))
 return CGF.Builder.CreateIntToPtr(index, pointer->getType());
 
-  if (width != DL.getTypeSizeInBits(PtrTy)) {
+  if (width != DL.getIndexTypeSizeInBits(PtrTy)) {
 // Zero-extend or sign-extend the pointer value according to
 // whether the index is signed or not.
-index = CGF.Builder.CreateIntCast(index, DL.getIntPtrType(PtrTy), isSigned,
+index = CGF.Builder.CreateIntCast(index, DL.getIndexType(PtrTy), isSigned,
   "idx.ext");
   }
 

diff  --git a/llvm/include/llvm/Analysis/PtrUseVisitor.h 
b/llvm/include/llvm/Analysis/PtrUseVisitor.h
index fbf04c841d30..05bca2226742 100644
--- a/llvm/include/llvm/Analysis/PtrUseVisitor.h
+++ b/llvm/include/llvm/Analysis/PtrUseVisitor.h
@@ -222,9 +222,9 @@ class PtrUseVisitor : protected InstVisitor,
 // offsets on this pointer.
 // FIXME: Support a vector of pointers.
 assert(I.getType()->isPointerTy());
-IntegerType *IntPtrTy = cast(DL.getIntPtrType(I.getType()));
+IntegerType *IntIdxTy = cast(DL.getIndexType(I.getType()));
 IsOffsetKnown = true;
-Offset = APInt(IntPtrTy->getBitWidth(), 0);
+Offset = APInt(IntIdxTy->getBitWidth(), 0);
 PI.reset();
 
 // Enqueue the uses of this pointer.

diff  --git a/llvm/include/llvm/Analysis/Utils/Local.h 
b/llvm/include/llvm/Analysis/Utils/Local.h
index 98b931f93451..ca505960cbeb 100644
--- a/llvm/include/llvm/Analysis/Utils/Local.h
+++ b/llvm/include/llvm/Analysis/Utils/Local.h
@@ -29,15 +29,15 @@ template 
 Value *EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP,
  bool NoAssumptions = false) {
   GEPOperator *GEPOp = cast(GEP);
-  Type *IntPtrTy = DL.getIntPtrType(GEP->getType());
-  Value *Result = Constant::getNullValue(IntPtrTy);
+  Type *IntIdxTy = DL.getIndexType(GEP->getType());
+  Value *Result = Constant::getNullValue(IntIdxTy);
 
   // If the GEP is inbounds, we know that none of the addressing operations 
will
   // overflow in a signed sense.
   bool isInBounds = GEPOp->isInBounds() && !NoAssumptions;
 
   // Build a mask for high order bits.
-  unsigned IntPtrWidth = IntPtrTy->getScalarType()->getIntegerBitWidth();
+  unsigned IntPtrWidth = IntIdxTy->getScalarType()->getIntegerBitWidth();
   uint64_t PtrSizeMask =
   std::numeric_limits::max() >> (64 - IntPtrWidth);
 
@@ -56,17 +56,17 @@ Value *EmitGEPOffset(IRBuilderTy *Builder, const DataLayout 
&DL, User *GEP,
 Size = DL.getStructLayout(STy)->getElementOffset(OpValue);
 
 if (Size)
-  Result = Builder->CreateAdd(Result, ConstantInt::get(IntPtrTy, Size),
+  Re

[clang] f798eb2 - Temporarily Revert "[DataLayout] Fix occurrences that size and range of pointers are assumed to be the same."

2019-12-12 Thread Nicola Zaghen via cfe-commits

Author: Nicola Zaghen
Date: 2019-12-12T10:29:54Z
New Revision: f798eb21eca97dc44ed40da52ece22780fb74230

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

LOG: Temporarily Revert "[DataLayout] Fix occurrences that size and range of 
pointers are assumed to be the same."

This reverts commit 5f6208778ff92567c57d7c1e2e740c284d7e69a5.

This caused failures in Transforms/PhaseOrdering/scev-custom-dl.ll
const: Assertion `getBitWidth() == CR.getBitWidth() && "ConstantRange types 
don't agree!"' failed.

Added: 


Modified: 
clang/lib/CodeGen/CGExprScalar.cpp
llvm/include/llvm/Analysis/PtrUseVisitor.h
llvm/include/llvm/Analysis/Utils/Local.h
llvm/lib/Analysis/ConstantFolding.cpp
llvm/lib/Analysis/InlineCost.cpp
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/lib/Analysis/Loads.cpp
llvm/lib/Analysis/MemoryBuiltins.cpp
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/lib/Analysis/ScalarEvolutionExpander.cpp
llvm/lib/Analysis/ValueTracking.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/lib/IR/DataLayout.cpp
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
llvm/lib/Transforms/Utils/Local.cpp
llvm/test/Transforms/InstCombine/gep-custom-dl.ll
llvm/test/Transforms/InstCombine/icmp-custom-dl.ll
llvm/test/Transforms/PhaseOrdering/scev-custom-dl.ll
llvm/test/Transforms/SimplifyCFG/switch_create-custom-dl.ll

Removed: 
llvm/test/Transforms/InstCombine/builtin-object-size-custom-dl.ll
llvm/test/Transforms/InstCombine/stdio-custom-dl.ll



diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index b8846162508e..b1dcbc51f58e 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -3264,10 +3264,10 @@ static Value *emitPointerArithmetic(CodeGenFunction 
&CGF,
expr->getRHS()))
 return CGF.Builder.CreateIntToPtr(index, pointer->getType());
 
-  if (width != DL.getIndexTypeSizeInBits(PtrTy)) {
+  if (width != DL.getTypeSizeInBits(PtrTy)) {
 // Zero-extend or sign-extend the pointer value according to
 // whether the index is signed or not.
-index = CGF.Builder.CreateIntCast(index, DL.getIndexType(PtrTy), isSigned,
+index = CGF.Builder.CreateIntCast(index, DL.getIntPtrType(PtrTy), isSigned,
   "idx.ext");
   }
 

diff  --git a/llvm/include/llvm/Analysis/PtrUseVisitor.h 
b/llvm/include/llvm/Analysis/PtrUseVisitor.h
index 05bca2226742..fbf04c841d30 100644
--- a/llvm/include/llvm/Analysis/PtrUseVisitor.h
+++ b/llvm/include/llvm/Analysis/PtrUseVisitor.h
@@ -222,9 +222,9 @@ class PtrUseVisitor : protected InstVisitor,
 // offsets on this pointer.
 // FIXME: Support a vector of pointers.
 assert(I.getType()->isPointerTy());
-IntegerType *IntIdxTy = cast(DL.getIndexType(I.getType()));
+IntegerType *IntPtrTy = cast(DL.getIntPtrType(I.getType()));
 IsOffsetKnown = true;
-Offset = APInt(IntIdxTy->getBitWidth(), 0);
+Offset = APInt(IntPtrTy->getBitWidth(), 0);
 PI.reset();
 
 // Enqueue the uses of this pointer.

diff  --git a/llvm/include/llvm/Analysis/Utils/Local.h 
b/llvm/include/llvm/Analysis/Utils/Local.h
index ca505960cbeb..98b931f93451 100644
--- a/llvm/include/llvm/Analysis/Utils/Local.h
+++ b/llvm/include/llvm/Analysis/Utils/Local.h
@@ -29,15 +29,15 @@ template 
 Value *EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP,
  bool NoAssumptions = false) {
   GEPOperator *GEPOp = cast(GEP);
-  Type *IntIdxTy = DL.getIndexType(GEP->getType());
-  Value *Result = Constant::getNullValue(IntIdxTy);
+  Type *IntPtrTy = DL.getIntPtrType(GEP->getType());
+  Value *Result = Constant::getNullValue(IntPtrTy);
 
   // If the GEP is inbounds, we know that none of the addressing operations 
will
   // overflow in a signed sense.
   bool isInBounds = GEPOp->isInBounds() && !NoAssumptions;
 
   // Build a mask for high order bits.
-  unsigned IntPtrWidth = IntIdxTy->getScalarType()->getIntegerBitWidth();
+  unsigned IntPtrWidth = IntPtrTy->getScalarType()->getIntegerBitWidth();
   uint64_t PtrSizeMask =
   std::numeric_limits::max() >> (64 - IntPtrWidth);
 
@@ -56,17 +56,17 @@ Value *EmitGEPOffset(IRBuilderTy *Builder, const DataLayout 
&DL, User *GEP,
 Size = DL.getStructLayout(STy)->getElementOffset(OpValue);
 
 if (Size)
-  Result = Builder->CreateAdd(Result, ConstantInt::get(IntIdxTy, Size),
+  Result = Builder->CreateAdd(Result, ConstantInt::get(IntPtrTy, Size),
   GEP->getName()+".offs");
 cont

[clang] 9757277 - Reland [DataLayout] Fix occurrences that size and range of pointers are assumed to be the same.

2019-12-13 Thread Nicola Zaghen via cfe-commits

Author: Nicola Zaghen
Date: 2019-12-13T14:30:21Z
New Revision: 97572775d2fe088d8059b3a9423f6d8539fafe33

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

LOG: Reland [DataLayout] Fix occurrences that size and range of pointers are 
assumed to be the same.

GEP index size can be specified in the DataLayout, introduced in D42123. 
However, there were still places
in which getIndexSizeInBits was used interchangeably with getPointerSizeInBits. 
This notably caused issues
with Instcombine's visitPtrToInt; but the unit tests was incorrect, so this 
remained undiscovered.

This fixes the buildbot failures.

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

Patch by Joseph Faulls!

Added: 
llvm/test/Transforms/InstCombine/builtin-object-size-custom-dl.ll
llvm/test/Transforms/InstCombine/stdio-custom-dl.ll

Modified: 
clang/lib/CodeGen/CGExprScalar.cpp
llvm/include/llvm/Analysis/PtrUseVisitor.h
llvm/include/llvm/Analysis/Utils/Local.h
llvm/lib/Analysis/ConstantFolding.cpp
llvm/lib/Analysis/InlineCost.cpp
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/lib/Analysis/Loads.cpp
llvm/lib/Analysis/MemoryBuiltins.cpp
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/lib/Analysis/ScalarEvolutionExpander.cpp
llvm/lib/Analysis/ValueTracking.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/lib/IR/DataLayout.cpp
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
llvm/lib/Transforms/Utils/Local.cpp
llvm/test/Transforms/InstCombine/gep-custom-dl.ll
llvm/test/Transforms/InstCombine/icmp-custom-dl.ll
llvm/test/Transforms/PhaseOrdering/scev-custom-dl.ll
llvm/test/Transforms/SimplifyCFG/switch_create-custom-dl.ll

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index b1dcbc51f58e..b8846162508e 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -3264,10 +3264,10 @@ static Value *emitPointerArithmetic(CodeGenFunction 
&CGF,
expr->getRHS()))
 return CGF.Builder.CreateIntToPtr(index, pointer->getType());
 
-  if (width != DL.getTypeSizeInBits(PtrTy)) {
+  if (width != DL.getIndexTypeSizeInBits(PtrTy)) {
 // Zero-extend or sign-extend the pointer value according to
 // whether the index is signed or not.
-index = CGF.Builder.CreateIntCast(index, DL.getIntPtrType(PtrTy), isSigned,
+index = CGF.Builder.CreateIntCast(index, DL.getIndexType(PtrTy), isSigned,
   "idx.ext");
   }
 

diff  --git a/llvm/include/llvm/Analysis/PtrUseVisitor.h 
b/llvm/include/llvm/Analysis/PtrUseVisitor.h
index fbf04c841d30..05bca2226742 100644
--- a/llvm/include/llvm/Analysis/PtrUseVisitor.h
+++ b/llvm/include/llvm/Analysis/PtrUseVisitor.h
@@ -222,9 +222,9 @@ class PtrUseVisitor : protected InstVisitor,
 // offsets on this pointer.
 // FIXME: Support a vector of pointers.
 assert(I.getType()->isPointerTy());
-IntegerType *IntPtrTy = cast(DL.getIntPtrType(I.getType()));
+IntegerType *IntIdxTy = cast(DL.getIndexType(I.getType()));
 IsOffsetKnown = true;
-Offset = APInt(IntPtrTy->getBitWidth(), 0);
+Offset = APInt(IntIdxTy->getBitWidth(), 0);
 PI.reset();
 
 // Enqueue the uses of this pointer.

diff  --git a/llvm/include/llvm/Analysis/Utils/Local.h 
b/llvm/include/llvm/Analysis/Utils/Local.h
index 98b931f93451..ca505960cbeb 100644
--- a/llvm/include/llvm/Analysis/Utils/Local.h
+++ b/llvm/include/llvm/Analysis/Utils/Local.h
@@ -29,15 +29,15 @@ template 
 Value *EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP,
  bool NoAssumptions = false) {
   GEPOperator *GEPOp = cast(GEP);
-  Type *IntPtrTy = DL.getIntPtrType(GEP->getType());
-  Value *Result = Constant::getNullValue(IntPtrTy);
+  Type *IntIdxTy = DL.getIndexType(GEP->getType());
+  Value *Result = Constant::getNullValue(IntIdxTy);
 
   // If the GEP is inbounds, we know that none of the addressing operations 
will
   // overflow in a signed sense.
   bool isInBounds = GEPOp->isInBounds() && !NoAssumptions;
 
   // Build a mask for high order bits.
-  unsigned IntPtrWidth = IntPtrTy->getScalarType()->getIntegerBitWidth();
+  unsigned IntPtrWidth = IntIdxTy->getScalarType()->getIntegerBitWidth();
   uint64_t PtrSizeMask =
   std::numeric_limits::max() >> (64 - IntPtrWidth);
 
@@ -56,17 +56,17 @@ Value *EmitGEPOffset(IRBuilderTy *Builder, const DataLayout 
&DL, User *GEP,
 Size = DL.getStructLayout(STy)->getElementOffset(OpValue);
 
 if (Size)
-  Result = Builder->CreateAdd(Result, Const