[clang] [llvm] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-06 Thread Youngsuk Kim via cfe-commits

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


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


[clang] [llvm] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-06 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

https://buildkite.com/llvm-project/github-pull-requests/builds/12872#018ba3cf-2050-4af1-b46a-55b5482323fc

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


[llvm] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-06 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 requested changes to this pull request.

Please update existing uses in `polly`, and rebase onto latest `main`.

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


[clang] 34ee69b - [clang][CGObjCMac] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-11-06 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-06T10:19:48-06:00
New Revision: 34ee69b4ce66280ccc65acc1799a5863de2f2aa6

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

LOG: [clang][CGObjCMac] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque ptr cleanup effort (NFC).

Added: 


Modified: 
clang/lib/CodeGen/CGObjCMac.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 6dd7ca64e5221bd..4ac8c4dc9a38745 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -2961,8 +2961,7 @@ llvm::Value 
*CGObjCMac::GenerateProtocolRef(CodeGenFunction &CGF,
   // resolved. Investigate. Its also wasteful to look this up over and over.
   LazySymbols.insert(&CGM.getContext().Idents.get("Protocol"));
 
-  return llvm::ConstantExpr::getBitCast(GetProtocolRef(PD),
-ObjCTypes.getExternalProtocolPtrTy());
+  return GetProtocolRef(PD);
 }
 
 void CGObjCCommonMac::GenerateProtocol(const ObjCProtocolDecl *PD) {
@@ -3182,7 +3181,7 @@ CGObjCMac::EmitProtocolList(Twine name,
 
   llvm::GlobalVariable *GV =
   CreateMetadataVar(name, values, section, CGM.getPointerAlign(), false);
-  return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.ProtocolListPtrTy);
+  return GV;
 }
 
 static void
@@ -3290,7 +3289,7 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine 
Name,
 
   llvm::GlobalVariable *GV =
   CreateMetadataVar(Name, values, Section, CGM.getPointerAlign(), true);
-  return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.PropertyListPtrTy);
+  return GV;
 }
 
 llvm::Constant *
@@ -3311,7 +3310,7 @@ CGObjCCommonMac::EmitProtocolMethodTypes(Twine Name,
 
   llvm::GlobalVariable *GV =
   CreateMetadataVar(Name, Init, Section, CGM.getPointerAlign(), true);
-  return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.Int8PtrPtrTy);
+  return GV;
 }
 
 /*
@@ -3804,7 +3803,7 @@ llvm::Constant *CGObjCMac::EmitIvarList(const 
ObjCImplementationDecl *ID,
   GV = CreateMetadataVar("OBJC_INSTANCE_VARIABLES_" + ID->getName(), ivarList,
  "__OBJC,__instance_vars,regular,no_dead_strip",
  CGM.getPointerAlign(), true);
-  return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.IvarListPtrTy);
+  return GV;
 }
 
 /// Build a struct objc_method_description constant for the given method.
@@ -3923,8 +3922,7 @@ llvm::Constant *CGObjCMac::emitMethodList(Twine name, 
MethodListType MLT,
 
 llvm::GlobalVariable *GV = CreateMetadataVar(prefix + name, values, 
section,
  CGM.getPointerAlign(), true);
-return llvm::ConstantExpr::getBitCast(GV,
-  
ObjCTypes.MethodDescriptionListPtrTy);
+return GV;
   }
 
   // Otherwise, it's an objc_method_list.
@@ -3941,7 +3939,7 @@ llvm::Constant *CGObjCMac::emitMethodList(Twine name, 
MethodListType MLT,
 
   llvm::GlobalVariable *GV = CreateMetadataVar(prefix + name, values, section,
CGM.getPointerAlign(), true);
-  return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.MethodListPtrTy);
+  return GV;
 }
 
 llvm::Function *CGObjCCommonMac::GenerateMethod(const ObjCMethodDecl *OMD,
@@ -3996,8 +3994,7 @@ CGObjCCommonMac::GenerateDirectMethod(const 
ObjCMethodDecl *OMD,
 Fn = llvm::Function::Create(MethodTy, llvm::GlobalValue::ExternalLinkage,
 "", &CGM.getModule());
 Fn->takeName(OldFn);
-OldFn->replaceAllUsesWith(
-llvm::ConstantExpr::getBitCast(Fn, OldFn->getType()));
+OldFn->replaceAllUsesWith(Fn);
 OldFn->eraseFromParent();
 
 // Replace the cached function in the map.
@@ -5204,7 +5201,7 @@ llvm::Constant *CGObjCMac::EmitModuleSymbols() {
   llvm::GlobalVariable *GV = CreateMetadataVar(
   "OBJC_SYMBOLS", values, "__OBJC,__symbols,regular,no_dead_strip",
   CGM.getPointerAlign(), true);
-  return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.SymtabPtrTy);
+  return GV;
 }
 
 llvm::Value *CGObjCMac::EmitClassRefFromId(CodeGenFunction &CGF,
@@ -5214,13 +5211,10 @@ llvm::Value 
*CGObjCMac::EmitClassRefFromId(CodeGenFunction &CGF,
   llvm::GlobalVariable *&Entry = ClassReferences[II];
 
   if (!Entry) {
-llvm::Constant *Casted =
-llvm::ConstantExpr::getBitCast(GetClassName(II->getName()),
-   ObjCTypes.ClassPtrTy);
-Entry = CreateMetadataVar(
-"OBJC_CLASS_REFERENCES_", Casted,
-"__OBJC,__cls_refs,literal_pointers,no_dead_strip",
-CGM.getPointerAlign(), true);
+Entry =
+CreateMetadataVar("OBJC_CLASS_REFERENCES_", 
GetClassName(II->getName()),
+  "__OBJC,__cls_refs,literal_pointers,no_dead_strip",
+  C

[clang] 0936a71 - [clang][CGObjCGNU] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-11-06 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-06T19:41:32-06:00
New Revision: 0936a718492d248a726b8e8d4529e4aa194bc8e9

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

LOG: [clang][CGObjCGNU] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque ptr cleanup effort (NFC).

Added: 


Modified: 
clang/lib/CodeGen/CGObjCGNU.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 0d2e74267e46c29..f02938cf799acd0 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -1014,8 +1014,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   if (CGM.getTriple().isOSBinFormatCOFF()) {
 
cast(isa)->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
   }
-} else if (isa->getType() != PtrToIdTy)
-  isa = llvm::ConstantExpr::getBitCast(isa, PtrToIdTy);
+}
 
 //  struct
 //  {
@@ -1108,10 +1107,9 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   std::pair v{ObjCStrGV, 0};
   EarlyInitList.emplace_back(Sym, v);
 }
-llvm::Constant *ObjCStr = llvm::ConstantExpr::getBitCast(ObjCStrGV, IdTy);
-ObjCStrings[Str] = ObjCStr;
-ConstantStrings.push_back(ObjCStr);
-return ConstantAddress(ObjCStr, IdElemTy, Align);
+ObjCStrings[Str] = ObjCStrGV;
+ConstantStrings.push_back(ObjCStrGV);
+return ConstantAddress(ObjCStrGV, IdElemTy, Align);
   }
 
   void PushProperty(ConstantArrayBuilder &PropertiesArray,
@@ -1193,9 +1191,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
ReferencedProtocols.end());
 SmallVector Protocols;
 for (const auto *PI : RuntimeProtocols)
-  Protocols.push_back(
-  llvm::ConstantExpr::getBitCast(GenerateProtocolRef(PI),
-ProtocolPtrTy));
+  Protocols.push_back(GenerateProtocolRef(PI));
 return GenerateProtocolList(Protocols);
   }
 
@@ -1305,7 +1301,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   llvm::GlobalValue::ExternalLinkage, nullptr, Name);
   GV->setAlignment(CGM.getPointerAlign().getAsAlign());
 }
-return llvm::ConstantExpr::getBitCast(GV, ProtocolPtrTy);
+return GV;
   }
 
   /// Existing protocol references.
@@ -1322,9 +1318,9 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   std::string RefName = SymbolForProtocolRef(Name);
   assert(!TheModule.getGlobalVariable(RefName));
   // Emit a reference symbol.
-  auto GV = new llvm::GlobalVariable(TheModule, ProtocolPtrTy,
-  false, llvm::GlobalValue::LinkOnceODRLinkage,
-  llvm::ConstantExpr::getBitCast(Protocol, ProtocolPtrTy), RefName);
+  auto GV = new llvm::GlobalVariable(TheModule, ProtocolPtrTy, false,
+ llvm::GlobalValue::LinkOnceODRLinkage,
+ Protocol, RefName);
   GV->setComdat(TheModule.getOrInsertComdat(RefName));
   GV->setSection(sectionName());
   GV->setAlignment(CGM.getPointerAlign().getAsAlign());
@@ -1381,9 +1377,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 auto RuntimeProtocols =
 GetRuntimeProtocolList(PD->protocol_begin(), PD->protocol_end());
 for (const auto *PI : RuntimeProtocols)
-  Protocols.push_back(
-  llvm::ConstantExpr::getBitCast(GenerateProtocolRef(PI),
-ProtocolPtrTy));
+  Protocols.push_back(GenerateProtocolRef(PI));
 llvm::Constant *ProtocolList = GenerateProtocolList(Protocols);
 
 // Collect information about methods
@@ -1420,8 +1414,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 GV->setSection(sectionName());
 GV->setComdat(TheModule.getOrInsertComdat(SymName));
 if (OldGV) {
-  OldGV->replaceAllUsesWith(llvm::ConstantExpr::getBitCast(GV,
-OldGV->getType()));
+  OldGV->replaceAllUsesWith(GV);
   OldGV->removeFromParent();
   GV->setName(SymName);
 }
@@ -2493,10 +2486,9 @@ ConstantAddress CGObjCGNU::GenerateConstantString(const 
StringLiteral *SL) {
   llvm::Constant *isa = TheModule.getNamedGlobal(Sym);
 
   if (!isa)
-isa = new llvm::GlobalVariable(TheModule, IdTy, /* isConstant */false,
-llvm::GlobalValue::ExternalWeakLinkage, nullptr, Sym);
-  else if (isa->getType() != PtrToIdTy)
-isa = llvm::ConstantExpr::getBitCast(isa, PtrToIdTy);
+isa = new llvm::GlobalVariable(TheModule, IdTy, /* isConstant */ false,
+   llvm::GlobalValue::ExternalWeakLinkage,
+   nullptr, Sym);
 
   ConstantInitBuilder Builder(CGM);
   auto Fields = Builder.beginStruct();



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

[clang] [mlir] [polly] [llvm] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-07 Thread Youngsuk Kim via cfe-commits

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

Thank you

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


[clang] 45ca24e - [clang] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-11-07 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-07T11:21:35-06:00
New Revision: 45ca24edc0b9f2541efb0ae3c668ee7af82e22f4

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

LOG: [clang] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque ptr cleanup effort (NFC).

Added: 


Modified: 
clang/lib/CodeGen/CGObjCGNU.cpp
clang/lib/CodeGen/CGVTables.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index f02938cf799acd0..519133055dcac59 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -1784,7 +1784,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 }
   }
   if (!IsCOFF)
-classFields.add(llvm::ConstantExpr::getBitCast(SuperClass, PtrTy));
+classFields.add(SuperClass);
   else
 classFields.addNullPointer(PtrTy);
 } else
@@ -1959,16 +1959,14 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 // Resolve the class aliases, if they exist.
 // FIXME: Class pointer aliases shouldn't exist!
 if (ClassPtrAlias) {
-  ClassPtrAlias->replaceAllUsesWith(
-  llvm::ConstantExpr::getBitCast(classStruct, IdTy));
+  ClassPtrAlias->replaceAllUsesWith(classStruct);
   ClassPtrAlias->eraseFromParent();
   ClassPtrAlias = nullptr;
 }
 if (auto Placeholder =
 TheModule.getNamedGlobal(SymbolForClass(className)))
   if (Placeholder != classStruct) {
-Placeholder->replaceAllUsesWith(
-llvm::ConstantExpr::getBitCast(classStruct, 
Placeholder->getType()));
+Placeholder->replaceAllUsesWith(classStruct);
 Placeholder->eraseFromParent();
 classStruct->setName(SymbolForClass(className));
   }
@@ -2415,7 +2413,7 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {
  false,
  llvm::GlobalValue::ExternalLinkage,
  nullptr, "__objc_id_type_info");
-return llvm::ConstantExpr::getBitCast(IDEHType, PtrToInt8Ty);
+return IDEHType;
   }
 
   const ObjCObjectPointerType *PT =
@@ -2429,9 +2427,8 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {
   std::string typeinfoName = "__objc_eh_typeinfo_" + className;
 
   // Return the existing typeinfo if it exists
-  llvm::Constant *typeinfo = TheModule.getGlobalVariable(typeinfoName);
-  if (typeinfo)
-return llvm::ConstantExpr::getBitCast(typeinfo, PtrToInt8Ty);
+  if (llvm::Constant *typeinfo = TheModule.getGlobalVariable(typeinfoName))
+return typeinfo;
 
   // Otherwise create it.
 
@@ -2495,9 +2492,7 @@ ConstantAddress CGObjCGNU::GenerateConstantString(const 
StringLiteral *SL) {
   Fields.add(isa);
   Fields.add(MakeConstantString(Str));
   Fields.addInt(IntTy, Str.size());
-  llvm::Constant *ObjCStr =
-Fields.finishAndCreateGlobal(".objc_str", Align);
-  ObjCStr = llvm::ConstantExpr::getBitCast(ObjCStr, PtrToInt8Ty);
+  llvm::Constant *ObjCStr = Fields.finishAndCreateGlobal(".objc_str", Align);
   ObjCStrings[Str] = ObjCStr;
   ConstantStrings.push_back(ObjCStr);
   return ConstantAddress(ObjCStr, Int8Ty, Align);
@@ -3060,8 +3055,7 @@ llvm::Constant *CGObjCGNU::GenerateClassStructure(
 Elements.finishAndCreateGlobal(ClassSym, CGM.getPointerAlign(), false,
llvm::GlobalValue::ExternalLinkage);
   if (ClassRef) {
-ClassRef->replaceAllUsesWith(llvm::ConstantExpr::getBitCast(Class,
-  ClassRef->getType()));
+ClassRef->replaceAllUsesWith(Class);
 ClassRef->removeFromParent();
 Class->setName(ClassSym);
   }
@@ -3227,9 +3221,7 @@ void CGObjCGNU::GenerateProtocol(const ObjCProtocolDecl 
*PD) {
   Elements.add(PropertyList);
   Elements.add(OptionalPropertyList);
   ExistingProtocols[ProtocolName] =
-llvm::ConstantExpr::getBitCast(
-  Elements.finishAndCreateGlobal(".objc_protocol", CGM.getPointerAlign()),
-  IdTy);
+  Elements.finishAndCreateGlobal(".objc_protocol", CGM.getPointerAlign());
 }
 void CGObjCGNU::GenerateProtocolHolderCategory() {
   // Collect information about instance methods
@@ -3263,9 +3255,8 @@ void CGObjCGNU::GenerateProtocolHolderCategory() {
ProtocolList.finishAndCreateGlobal(".objc_protocol_list",
   CGM.getPointerAlign()),
PtrTy);
-  Categories.push_back(llvm::ConstantExpr::getBitCast(
-Elements.finishAndCreateGlobal("", CGM.getPointerAlign()),
-PtrTy));
+  Categories.push_back(
+  Elements.finishAndCreateGlobal("", CGM.getPointerAlign()));
 }
 
 /// Libobjc2 uses a bitfield representation where small(ish) bitfields are
@@ -3736,7 +3727,6 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
 
 statics = allStaticsA

[clang] [llvm] [clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast (NFC) (PR #68277)

2023-11-11 Thread Youngsuk Kim via cfe-commits


@@ -1123,9 +1123,7 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
 if (!CurFnInfo->getReturnInfo().getIndirectByVal()) {
   ReturnValuePointer =
   CreateDefaultAlignTempAlloca(Int8PtrTy, "result.ptr");
-  Builder.CreateStore(Builder.CreatePointerBitCastOrAddrSpaceCast(
-  ReturnValue.getPointer(), Int8PtrTy),
-  ReturnValuePointer);
+  Builder.CreateStore(ReturnValue.getPointer(), ReturnValuePointer);

JOE1994 wrote:

> But even if it would cast away an address space it seems a bit weird.

Yes, I agree..

> (And maybe the "result.ptr" should be created with 
> ReturnValue.getPointer().getType() rather than using Int8PtrTy. Although I 
> consider that as out of scope for this patch.)

I also agree.
Since, adding the change to this revision doesn't add new failures with `ninja 
check-clang`, I think it can be merged to this patch. I'll add the change to 
this revision.

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


[clang] [llvm] [clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast (NFC) (PR #68277)

2023-11-11 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 updated 
https://github.com/llvm/llvm-project/pull/68277

>From 2c3fb032e7fdefa553ed4833bbeed8852eb6a410 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Mon, 2 Oct 2023 12:28:33 -0400
Subject: [PATCH 1/4] [clang] Replace uses of
 CreatePointerBitCastOrAddrSpaceCast (NFC)

With opaque pointers, CreatePointerBitCastOrAddrSpaceCast is same as 
CreateAddrSpaceCast.
Replace or remove uses of CreatePointerBitCastOrAddrSpaceCast.

Opaque pointer cleanup effort.
---
 clang/lib/CodeGen/CGCall.cpp  | 2 +-
 clang/lib/CodeGen/CodeGenFunction.cpp | 4 +---
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 3 ---
 clang/lib/CodeGen/TargetInfo.cpp  | 2 +-
 llvm/include/llvm/IR/IRBuilder.h  | 2 ++
 5 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 93e16575042c4da..b0d1fcd26a5f413 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1376,7 +1376,7 @@ static void CreateCoercedStore(llvm::Value *Src,
   llvm::PointerType *DstPtrTy = llvm::dyn_cast(DstTy);
   if (SrcPtrTy && DstPtrTy &&
   SrcPtrTy->getAddressSpace() != DstPtrTy->getAddressSpace()) {
-Src = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(Src, DstTy);
+Src = CGF.Builder.CreateAddrSpaceCast(Src, DstTy);
 CGF.Builder.CreateStore(Src, Dst, DstIsVolatile);
 return;
   }
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 9b21f428b0af7f5..2f1954fad80f159 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1123,9 +1123,7 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
 if (!CurFnInfo->getReturnInfo().getIndirectByVal()) {
   ReturnValuePointer =
   CreateDefaultAlignTempAlloca(Int8PtrTy, "result.ptr");
-  Builder.CreateStore(Builder.CreatePointerBitCastOrAddrSpaceCast(
-  ReturnValue.getPointer(), Int8PtrTy),
-  ReturnValuePointer);
+  Builder.CreateStore(ReturnValue.getPointer(), ReturnValuePointer);
 }
   } else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::InAlloca &&
  !hasScalarEvaluationKind(CurFnInfo->getReturnType())) {
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 0c89871420bdd3d..f7ef9503aa61033 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -3088,9 +3088,6 @@ void ItaniumCXXABI::EmitThreadLocalInitFuncs(
   CharUnits Align = CGM.getContext().getDeclAlign(VD);
   Val = Builder.CreateAlignedLoad(Var->getValueType(), Val, Align);
 }
-if (Val->getType() != Wrapper->getReturnType())
-  Val = Builder.CreatePointerBitCastOrAddrSpaceCast(
-  Val, Wrapper->getReturnType(), "");
 
 Builder.CreateRet(Val);
   }
diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp
index 3d79f92137abc79..60224d458f6a262 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -137,7 +137,7 @@ llvm::Value *TargetCodeGenInfo::performAddrSpaceCast(
   if (auto *C = dyn_cast(Src))
 return performAddrSpaceCast(CGF.CGM, C, SrcAddr, DestAddr, DestTy);
   // Try to preserve the source's name to make IR more readable.
-  return CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
+  return CGF.Builder.CreateAddrSpaceCast(
   Src, DestTy, Src->hasName() ? Src->getName() + ".ascast" : "");
 }
 
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index c9f243fdb12e404..a32ec9a66fedfa8 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -2138,6 +2138,8 @@ class IRBuilderBase {
 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
   }
 
+  // With opaque pointers enabled, this is same as CreateAddressSpaceCast.
+  // TODO: Replace uses of this method and remove the method itself.
   Value *CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy,
  const Twine &Name = "") {
 if (V->getType() == DestTy)

>From 578bc43ac6bd066052803e76e1f3eb38b9798994 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Thu, 5 Oct 2023 21:46:26 -0400
Subject: [PATCH 2/4] Update comment for CreatePointerBitCastOrAddrSpaceCast

---
 llvm/include/llvm/IR/IRBuilder.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index a32ec9a66fedfa8..a2fab842b1d0355 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -2138,7 +2138,7 @@ class IRBuilderBase {
 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
   }
 
-  // With opaque pointers enabled, this is same as CreateAddressSpaceCast.
+  // With opaque pointers enabled, this can be substituted with 
CreateAddrSpaceCast.
   // TODO: Replace uses of this method a

[clang] [llvm] [clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast (NFC) (PR #68277)

2023-11-11 Thread Youngsuk Kim via cfe-commits

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


[clang] [clang][CGExprScalar] Remove no-op ptr-to-ptr bitcast (NFC) (PR #72072)

2023-11-12 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 created 
https://github.com/llvm/llvm-project/pull/72072

Remove bitcast added back in dcd74716f9d18 .

>From b9db2565d3d2d251bde7cd84b704861d5b41bd14 Mon Sep 17 00:00:00 2001
From: JOE1994 
Date: Sun, 12 Nov 2023 20:04:44 -0500
Subject: [PATCH] [clang][CGExprScalar] Remove no-op ptr-to-ptr bitcast (NFC)

Remove bitcast added back in dcd74716f9d18 .
---
 clang/lib/CodeGen/CGExprScalar.cpp | 8 
 1 file changed, 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 1a7a3f97bb779a0..2faab20fc069ee7 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2227,14 +2227,6 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 llvm::Value *V = CE->changesVolatileQualification()
  ? EmitLoadOfLValue(CE)
  : Visit(const_cast(E));
-if (V) {
-  // CK_NoOp can model a pointer qualification conversion, which can remove
-  // an array bound and change the IR type.
-  // FIXME: Once pointee types are removed from IR, remove this.
-  llvm::Type *T = ConvertType(DestTy);
-  if (T != V->getType())
-V = Builder.CreateBitCast(V, T);
-}
 return V;
   }
 

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


[clang] [clang][CGExprScalar] Remove no-op ptr-to-ptr bitcast (NFC) (PR #72072)

2023-11-13 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 updated 
https://github.com/llvm/llvm-project/pull/72072

>From b9db2565d3d2d251bde7cd84b704861d5b41bd14 Mon Sep 17 00:00:00 2001
From: JOE1994 
Date: Sun, 12 Nov 2023 20:04:44 -0500
Subject: [PATCH 1/2] [clang][CGExprScalar] Remove no-op ptr-to-ptr bitcast
 (NFC)

Remove bitcast added back in dcd74716f9d18 .
---
 clang/lib/CodeGen/CGExprScalar.cpp | 8 
 1 file changed, 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 1a7a3f97bb779a0..2faab20fc069ee7 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2227,14 +2227,6 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 llvm::Value *V = CE->changesVolatileQualification()
  ? EmitLoadOfLValue(CE)
  : Visit(const_cast(E));
-if (V) {
-  // CK_NoOp can model a pointer qualification conversion, which can remove
-  // an array bound and change the IR type.
-  // FIXME: Once pointee types are removed from IR, remove this.
-  llvm::Type *T = ConvertType(DestTy);
-  if (T != V->getType())
-V = Builder.CreateBitCast(V, T);
-}
 return V;
   }
 

>From f5e09e6ac45919a6e1fac6e4ee4520bda8aa502b Mon Sep 17 00:00:00 2001
From: JOE1994 
Date: Mon, 13 Nov 2023 10:02:28 -0500
Subject: [PATCH 2/2] Return immediately instead of storing retval to
 intermediate variable

---
 clang/lib/CodeGen/CGExprScalar.cpp | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 2faab20fc069ee7..641a984f2f1a0ec 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2224,10 +2224,8 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 return Visit(const_cast(E));
 
   case CK_NoOp: {
-llvm::Value *V = CE->changesVolatileQualification()
- ? EmitLoadOfLValue(CE)
- : Visit(const_cast(E));
-return V;
+return CE->changesVolatileQualification() ? EmitLoadOfLValue(CE)
+  : Visit(const_cast(E));
   }
 
   case CK_BaseToDerived: {

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


[clang] [clang][CGExprScalar] Remove no-op ptr-to-ptr bitcast (NFC) (PR #72072)

2023-11-13 Thread Youngsuk Kim via cfe-commits


@@ -2227,14 +2227,6 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 llvm::Value *V = CE->changesVolatileQualification()
  ? EmitLoadOfLValue(CE)
  : Visit(const_cast(E));
-if (V) {
-  // CK_NoOp can model a pointer qualification conversion, which can remove
-  // an array bound and change the IR type.
-  // FIXME: Once pointee types are removed from IR, remove this.
-  llvm::Type *T = ConvertType(DestTy);
-  if (T != V->getType())
-V = Builder.CreateBitCast(V, T);
-}
 return V;

JOE1994 wrote:

I added a follow-up commit for this. Thank you!

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


[clang] [clang][CGExprScalar] Remove no-op ptr-to-ptr bitcast (NFC) (PR #72072)

2023-11-13 Thread Youngsuk Kim via cfe-commits

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


[clang] b4db24e - [CGOpenMPRuntimeGPU] Replace unneeded use of CreatePointerBitCastOrAddrSpaceCast (NFC)

2023-11-18 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-18T04:17:46-06:00
New Revision: b4db24e33008660d11d703c19d8affaf5f9a843e

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

LOG: [CGOpenMPRuntimeGPU] Replace unneeded use of 
CreatePointerBitCastOrAddrSpaceCast (NFC)

Opaque ptr cleanup effort (NFC)

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index abecf5250f4cf96..2f7dd83bd2d65c9 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1418,9 +1418,7 @@ static llvm::Value *castValueToType(CodeGenFunction &CGF, 
llvm::Value *Val,
 return CGF.Builder.CreateIntCast(Val, LLVMCastTy,
  CastTy->hasSignedIntegerRepresentation());
   Address CastItem = CGF.CreateMemTemp(CastTy);
-  Address ValCastItem = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
-  CastItem, Val->getType()->getPointerTo(CastItem.getAddressSpace()),
-  Val->getType());
+  Address ValCastItem = CastItem.withElementType(Val->getType());
   CGF.EmitStoreOfScalar(Val, ValCastItem, /*Volatile=*/false, ValTy,
 LValueBaseInfo(AlignmentSource::Type),
 TBAAAccessInfo());



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


[clang] a540808 - [CGObjCGNU] Remove unneeded method 'CGObjCGNUstep2::EnforceType' (NFC)

2023-11-18 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-18T14:06:45-06:00
New Revision: a540808de254b18b304aa0915638a0900b36d9fa

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

LOG: [CGObjCGNU] Remove unneeded method 'CGObjCGNUstep2::EnforceType' (NFC)

Method CGObjCGNUstep2::EnforceType is called from 2 call-sites to perform
bitcasts which are no-ops given that opaque pointers are enabled in LLVM.

Remove the method. Opaque ptr cleanup effort (NFC).

Added: 


Modified: 
clang/lib/CodeGen/CGObjCGNU.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index bd9e8b2b3bf..01fd8f5a00ee39f 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -1421,11 +1421,6 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 Protocol = GV;
 return GV;
   }
-  llvm::Constant *EnforceType(llvm::Constant *Val, llvm::Type *Ty) {
-if (Val->getType() == Ty)
-  return Val;
-return llvm::ConstantExpr::getBitCast(Val, Ty);
-  }
   llvm::Value *GetTypedSelector(CodeGenFunction &CGF, Selector Sel,
 const std::string &TypeEncoding) override {
 return GetConstantSelector(Sel, TypeEncoding);
@@ -1462,7 +1457,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 auto SelVarName = (StringRef(".objc_selector_") + Sel.getAsString() + "_" +
   MangledTypes).str();
 if (auto *GV = TheModule.getNamedGlobal(SelVarName))
-  return EnforceType(GV, SelectorTy);
+  return GV;
 ConstantInitBuilder builder(CGM);
 auto SelBuilder = builder.beginStruct();
 SelBuilder.add(ExportUniqueString(Sel.getAsString(), ".objc_sel_name_",
@@ -1473,8 +1468,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 GV->setComdat(TheModule.getOrInsertComdat(SelVarName));
 GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
 GV->setSection(sectionName());
-auto *SelVal = EnforceType(GV, SelectorTy);
-return SelVal;
+return GV;
   }
   llvm::StructType *emptyStruct = nullptr;
 



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


[clang] b08960f - [CGObjCMac] Replace calls to ConstantAggregateBuilderBase::addBitCast (NFC)

2023-11-18 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-18T17:03:48-06:00
New Revision: b08960f1e96d64874486354c16b4116c5f8f

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

LOG: [CGObjCMac] Replace calls to ConstantAggregateBuilderBase::addBitCast (NFC)

Replace calls to `ConstantAggregateBuilderBase::addBitCast` that involve a
no-op ptr-to-ptr bitcast.

Opaque ptr cleanup effort (NFC)

Added: 


Modified: 
clang/lib/CodeGen/CGObjCMac.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 4ac8c4dc9a38745..ba52b23be018b85 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -2014,7 +2014,7 @@ CGObjCCommonMac::GenerateConstantNSString(const 
StringLiteral *Literal) {
   // Don't enforce the target's minimum global alignment, since the only use
   // of the string is via this class initializer.
   GV->setAlignment(llvm::Align(1));
-  Fields.addBitCast(GV, CGM.Int8PtrTy);
+  Fields.add(GV);
 
   // String length.
   Fields.addInt(CGM.IntTy, StringLength);
@@ -3557,8 +3557,7 @@ void CGObjCMac::GenerateClass(const 
ObjCImplementationDecl *ID) {
 // Record a reference to the super class.
 LazySymbols.insert(Super->getIdentifier());
 
-values.addBitCast(GetClassName(Super->getObjCRuntimeNameAsString()),
-  ObjCTypes.ClassPtrTy);
+values.add(GetClassName(Super->getObjCRuntimeNameAsString()));
   } else {
 values.addNullPointer(ObjCTypes.ClassPtrTy);
   }
@@ -3612,14 +3611,12 @@ llvm::Constant *CGObjCMac::EmitMetaClass(const 
ObjCImplementationDecl *ID,
   const ObjCInterfaceDecl *Root = ID->getClassInterface();
   while (const ObjCInterfaceDecl *Super = Root->getSuperClass())
 Root = Super;
-  values.addBitCast(GetClassName(Root->getObjCRuntimeNameAsString()),
-ObjCTypes.ClassPtrTy);
+  values.add(GetClassName(Root->getObjCRuntimeNameAsString()));
   // The super class for the metaclass is emitted as the name of the
   // super class. The runtime fixes this up to point to the
   // *metaclass* for the super class.
   if (ObjCInterfaceDecl *Super = ID->getClassInterface()->getSuperClass()) {
-values.addBitCast(GetClassName(Super->getObjCRuntimeNameAsString()),
-  ObjCTypes.ClassPtrTy);
+values.add(GetClassName(Super->getObjCRuntimeNameAsString()));
   } else {
 values.addNullPointer(ObjCTypes.ClassPtrTy);
   }
@@ -3815,8 +3812,7 @@ llvm::Constant *CGObjCMac::EmitIvarList(const 
ObjCImplementationDecl *ID,
 void CGObjCMac::emitMethodDescriptionConstant(ConstantArrayBuilder &builder,
   const ObjCMethodDecl *MD) {
   auto description = builder.beginStruct(ObjCTypes.MethodDescriptionTy);
-  description.addBitCast(GetMethodVarName(MD->getSelector()),
- ObjCTypes.SelectorPtrTy);
+  description.add(GetMethodVarName(MD->getSelector()));
   description.add(GetMethodVarType(MD));
   description.finishAndAddTo(builder);
 }
@@ -3834,10 +3830,9 @@ void CGObjCMac::emitMethodConstant(ConstantArrayBuilder 
&builder,
   assert(fn && "no definition registered for method");
 
   auto method = builder.beginStruct(ObjCTypes.MethodTy);
-  method.addBitCast(GetMethodVarName(MD->getSelector()),
-ObjCTypes.SelectorPtrTy);
+  method.add(GetMethodVarName(MD->getSelector()));
   method.add(GetMethodVarType(MD));
-  method.addBitCast(fn, ObjCTypes.Int8PtrTy);
+  method.add(fn);
   method.finishAndAddTo(builder);
 }
 
@@ -5191,10 +5186,10 @@ llvm::Constant *CGObjCMac::EmitModuleSymbols() {
   if (ID->isWeakImported() && !IMP->isWeakImported())
 DefinedClasses[i]->setLinkage(llvm::GlobalVariable::ExternalLinkage);
 
-array.addBitCast(DefinedClasses[i], ObjCTypes.Int8PtrTy);
+array.add(DefinedClasses[i]);
   }
   for (unsigned i=0; igetSelector()),
-ObjCTypes.SelectorPtrTy);
+  method.add(GetMethodVarName(MD->getSelector()));
   method.add(GetMethodVarType(MD));
 
   if (forProtocol) {
@@ -6745,7 +6739,7 @@ void 
CGObjCNonFragileABIMac::emitMethodConstant(ConstantArrayBuilder &builder,
   } else {
 llvm::Function *fn = GetMethodDefinition(MD);
 assert(fn && "no definition for method?");
-method.addBitCast(fn, ObjCTypes.Int8PtrProgramASTy);
+method.add(fn);
   }
 
   method.finishAndAddTo(builder);



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


[clang] 695662b - [clang] Remove ConstantAggregateBuilderBase::addBitCast (NFC)

2023-11-18 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-18T17:46:08-06:00
New Revision: 695662b00c993dc33f7196c6d156c967a0aad6af

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

LOG: [clang] Remove ConstantAggregateBuilderBase::addBitCast (NFC)

* Replace all existing uses of ConstantAggregateBuilderBase::addBitCast,
  as they involve a no-op ptr-to-ptr bitcast
* Remove method ConstantAggregateBuilderBase::addBitCast

Opaque ptr cleanup effort (NFC)

Added: 


Modified: 
clang/include/clang/CodeGen/ConstantInitBuilder.h
clang/lib/CodeGen/CGObjCGNU.cpp

Removed: 




diff  --git a/clang/include/clang/CodeGen/ConstantInitBuilder.h 
b/clang/include/clang/CodeGen/ConstantInitBuilder.h
index 9e0d0fa0d8e8243..498acfd38013183 100644
--- a/clang/include/clang/CodeGen/ConstantInitBuilder.h
+++ b/clang/include/clang/CodeGen/ConstantInitBuilder.h
@@ -204,11 +204,6 @@ class ConstantAggregateBuilderBase {
 add(llvm::ConstantPointerNull::get(ptrTy));
   }
 
-  /// Add a bitcast of a value to a specific type.
-  void addBitCast(llvm::Constant *value, llvm::Type *type) {
-add(llvm::ConstantExpr::getBitCast(value, type));
-  }
-
   /// Add a bunch of new values to this initializer.
   void addAll(llvm::ArrayRef values) {
 assert(!Finished && "cannot add more values after finishing builder");

diff  --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 01fd8f5a00ee39f..68ec457e426a933 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -1725,9 +1725,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   SmallVector ClassMethods;
   ClassMethods.insert(ClassMethods.begin(), OID->classmeth_begin(),
   OID->classmeth_end());
-  metaclassFields.addBitCast(
-  GenerateMethodList(className, "", ClassMethods, true),
-  PtrTy);
+  metaclassFields.add(
+  GenerateMethodList(className, "", ClassMethods, true));
 }
 // void *dtable;
 metaclassFields.addNullPointer(PtrTy);
@@ -1894,9 +1893,9 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 if (InstanceMethods.size() == 0)
   classFields.addNullPointer(PtrTy);
 else
-  classFields.addBitCast(
-  GenerateMethodList(className, "", InstanceMethods, false),
-  PtrTy);
+  classFields.add(
+  GenerateMethodList(className, "", InstanceMethods, false));
+
 // void *dtable;
 classFields.addNullPointer(PtrTy);
 // IMP cxx_construct;
@@ -2887,14 +2886,14 @@ GenerateMethodList(StringRef ClassName,
 assert(FnPtr && "Can't generate metadata for method that doesn't exist");
 auto Method = MethodArray.beginStruct(ObjCMethodTy);
 if (isV2ABI) {
-  Method.addBitCast(FnPtr, IMPTy);
+  Method.add(FnPtr);
   Method.add(GetConstantSelector(OMD->getSelector(),
   Context.getObjCEncodingForMethodDecl(OMD)));
   Method.add(MakeConstantString(Context.getObjCEncodingForMethodDecl(OMD, 
true)));
 } else {
   Method.add(MakeConstantString(OMD->getSelector().getAsString()));
   
Method.add(MakeConstantString(Context.getObjCEncodingForMethodDecl(OMD)));
-  Method.addBitCast(FnPtr, IMPTy);
+  Method.add(FnPtr);
 }
 Method.finishAndAddTo(MethodArray);
   }
@@ -2993,7 +2992,7 @@ llvm::Constant *CGObjCGNU::GenerateClassStructure(
   // Fill in the structure
 
   // isa
-  Elements.addBitCast(MetaClass, PtrToInt8Ty);
+  Elements.add(MetaClass);
   // super_class
   Elements.add(SuperClass);
   // name
@@ -3022,7 +3021,7 @@ llvm::Constant *CGObjCGNU::GenerateClassStructure(
   // sibling_class
   Elements.add(NULLPtr);
   // protocols
-  Elements.addBitCast(Protocols, PtrTy);
+  Elements.add(Protocols);
   // gc_object_type
   Elements.add(NULLPtr);
   // abi_version
@@ -3094,7 +3093,7 @@ CGObjCGNU::GenerateProtocolList(ArrayRef 
Protocols) {
 } else {
   protocol = value->getValue();
 }
-Elements.addBitCast(protocol, PtrToInt8Ty);
+Elements.add(protocol);
   }
   Elements.finishAndAddTo(ProtocolList);
   return ProtocolList.finishAndCreateGlobal(".objc_protocol_list",
@@ -3224,11 +3223,9 @@ void CGObjCGNU::GenerateProtocolHolderCategory() {
   Elements.add(MakeConstantString(CategoryName));
   Elements.add(MakeConstantString(ClassName));
   // Instance method list
-  Elements.addBitCast(GenerateMethodList(
-  ClassName, CategoryName, {}, false), PtrTy);
+  Elements.add(GenerateMethodList(ClassName, CategoryName, {}, false));
   // Class method list
-  Elements.addBitCast(GenerateMethodList(
-  ClassName, CategoryName, {}, true), PtrTy);
+  Elements.add(GenerateMethodList(ClassName, CategoryName, {}, true));
 
   // Protocol list
   ConstantInitBuilder ProtocolListBuilder(CGM);
@@ -3238,13 +3235,11 @@ void CGObj

[clang] ed73121 - [CodeGenModule] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-11-20 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-20T16:21:21-06:00
New Revision: ed73121ffeb636e75162f116bfeca56e7ec310de

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

LOG: [CodeGenModule] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque ptr cleanup effort (NFC)

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index f1b900be74b2cdf..7cdf50a281cd278 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1983,9 +1983,9 @@ void CodeGenModule::EmitCtorList(CtorList &Fns, const 
char *GlobalName) {
   for (const auto &I : Fns) {
 auto ctor = ctors.beginStruct(CtorStructTy);
 ctor.addInt(Int32Ty, I.Priority);
-ctor.add(llvm::ConstantExpr::getBitCast(I.Initializer, CtorPFTy));
+ctor.add(I.Initializer);
 if (I.AssociatedData)
-  ctor.add(llvm::ConstantExpr::getBitCast(I.AssociatedData, VoidPtrTy));
+  ctor.add(I.AssociatedData);
 else
   ctor.addNullPointer(VoidPtrTy);
 ctor.finishAndAddTo(ctors);
@@ -4555,9 +4555,7 @@ llvm::Constant *CodeGenModule::GetFunctionStart(const 
ValueDecl *Decl) {
   llvm::GlobalValue *F =
   cast(GetAddrOfFunction(Decl)->stripPointerCasts());
 
-  return llvm::ConstantExpr::getBitCast(
-  llvm::NoCFIValue::get(F),
-  llvm::PointerType::get(VMContext, F->getAddressSpace()));
+  return llvm::NoCFIValue::get(F);
 }
 
 static const FunctionDecl *



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


[clang] [clang][CodeGen] Remove ptr-to-ptr bitcasts (NFC) (PR #73020)

2023-11-21 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 created 
https://github.com/llvm/llvm-project/pull/73020

Opaque ptr cleanup effort

>From 30cff5f1f27e047247ae126bb4b2d1c6103f7022 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Tue, 21 Nov 2023 11:16:23 -0600
Subject: [PATCH] [clang][CodeGen] Remove ptr-to-ptr bitcasts (NFC)

Opaque ptr cleanup effort
---
 clang/lib/CodeGen/CGBuiltin.cpp | 13 -
 clang/lib/CodeGen/CGStmt.cpp|  3 +--
 2 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 710e4c162103b41..c83ea966fdeadc6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5745,12 +5745,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Address DestAddr = EmitMSVAListRef(E->getArg(0));
 Address SrcAddr = EmitMSVAListRef(E->getArg(1));
 
-llvm::Type *BPP = Int8PtrPtrTy;
-
-DestAddr = Address(Builder.CreateBitCast(DestAddr.getPointer(), BPP, "cp"),
-   Int8PtrTy, DestAddr.getAlignment());
-SrcAddr = Address(Builder.CreateBitCast(SrcAddr.getPointer(), BPP, "ap"),
-  Int8PtrTy, SrcAddr.getAlignment());
+DestAddr = DestAddr.withElementType(Int8PtrTy);
+SrcAddr = SrcAddr.withElementType(Int8PtrTy);
 
 Value *ArgPtr = Builder.CreateLoad(SrcAddr, "ap.val");
 return RValue::get(Builder.CreateStore(ArgPtr, DestAddr));
@@ -8424,8 +8420,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned 
BuiltinID,
 }
 
 Value *LdPtr = EmitScalarExpr(E->getArg(0));
-Value *Val = Builder.CreateCall(F, Builder.CreateBitCast(LdPtr, Int8PtrTy),
-"ldrexd");
+Value *Val = Builder.CreateCall(F, LdPtr, "ldrexd");
 
 Value *Val0 = Builder.CreateExtractValue(Val, 1);
 Value *Val1 = Builder.CreateExtractValue(Val, 0);
@@ -8483,7 +8478,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned 
BuiltinID,
 
 Value *Arg0 = Builder.CreateExtractValue(Val, 0);
 Value *Arg1 = Builder.CreateExtractValue(Val, 1);
-Value *StPtr = Builder.CreateBitCast(EmitScalarExpr(E->getArg(1)), 
Int8PtrTy);
+Value *StPtr = EmitScalarExpr(E->getArg(1));
 return Builder.CreateCall(F, {Arg0, Arg1, StPtr}, "strexd");
   }
 
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index c719df1bfa05036..a7100c8fae2eff9 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -1299,8 +1299,7 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) 
{
 SLocPtr->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
 CGM.getSanitizerMetadata()->disableSanitizerForGlobal(SLocPtr);
 assert(ReturnLocation.isValid() && "No valid return location");
-Builder.CreateStore(Builder.CreateBitCast(SLocPtr, Int8PtrTy),
-ReturnLocation);
+Builder.CreateStore(SLocPtr, ReturnLocation);
   }
 
   // Returning from an outlined SEH helper is UB, and we already warn on it.

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


[clang] 5c15922 - [clang] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-10-27 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-10-27T14:59:42-05:00
New Revision: 5c159222627e2201bee73c401be3b76f995b2336

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

LOG: [clang] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque pointer cleanup effort. NFC.

Added: 


Modified: 
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGExprCXX.cpp
clang/lib/CodeGen/CGNonTrivialStruct.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 4d4c94d008c9dfc..9e4319d27858e6f 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -1358,7 +1358,6 @@ llvm::Value 
*CodeGenFunction::EmitLifetimeStart(llvm::TypeSize Size,
  "Pointer should be in alloca address space");
   llvm::Value *SizeV = llvm::ConstantInt::get(
   Int64Ty, Size.isScalable() ? -1 : Size.getFixedValue());
-  Addr = Builder.CreateBitCast(Addr, AllocaInt8PtrTy);
   llvm::CallInst *C =
   Builder.CreateCall(CGM.getLLVMLifetimeStartFn(), {SizeV, Addr});
   C->setDoesNotThrow();
@@ -1369,7 +1368,6 @@ void CodeGenFunction::EmitLifetimeEnd(llvm::Value *Size, 
llvm::Value *Addr) {
   assert(Addr->getType()->getPointerAddressSpace() ==
  CGM.getDataLayout().getAllocaAddrSpace() &&
  "Pointer should be in alloca address space");
-  Addr = Builder.CreateBitCast(Addr, AllocaInt8PtrTy);
   llvm::CallInst *C =
   Builder.CreateCall(CGM.getLLVMLifetimeEndFn(), {Size, Addr});
   C->setDoesNotThrow();

diff  --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 2e7059cc8f5b639..4bd8462ab5f8be6 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1106,9 +1106,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
   // element.  TODO: some of these stores can be trivially
   // observed to be unnecessary.
   if (EndOfInit.isValid()) {
-auto FinishedPtr =
-  Builder.CreateBitCast(CurPtr.getPointer(), BeginPtr.getType());
-Builder.CreateStore(FinishedPtr, EndOfInit);
+Builder.CreateStore(CurPtr.getPointer(), EndOfInit);
   }
   // FIXME: If the last initializer is an incomplete initializer list for
   // an array, and we have an array filler, we can fold together the two

diff  --git a/clang/lib/CodeGen/CGNonTrivialStruct.cpp 
b/clang/lib/CodeGen/CGNonTrivialStruct.cpp
index 3d2b1b8b2f78d31..15c4a3e706c9d9a 100644
--- a/clang/lib/CodeGen/CGNonTrivialStruct.cpp
+++ b/clang/lib/CodeGen/CGNonTrivialStruct.cpp
@@ -367,8 +367,6 @@ template  struct GenFuncBase {
 CGF.Builder.CreateNUWMul(BaseEltSizeVal, NumElts);
 llvm::Value *DstArrayEnd = CGF.Builder.CreateInBoundsGEP(
 CGF.Int8Ty, DstAddr.getPointer(), SizeInBytes);
-DstArrayEnd = CGF.Builder.CreateBitCast(
-DstArrayEnd, CGF.CGM.Int8PtrPtrTy, "dstarray.end");
 llvm::BasicBlock *PreheaderBB = CGF.Builder.GetInsertBlock();
 
 // Create the header block and insert the phi instructions.

diff  --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index d623f8f63ae56c4..b6f941052abee85 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -4449,7 +4449,7 @@ void MicrosoftCXXABI::emitThrow(CodeGenFunction &CGF, 
const CXXThrowExpr *E) {
 
   // Call into the runtime to throw the exception.
   llvm::Value *Args[] = {
-CGF.Builder.CreateBitCast(AI.getPointer(), CGM.Int8PtrTy),
+AI.getPointer(),
 TI
   };
   CGF.EmitNoreturnRuntimeCallOrInvoke(getThrowFn(), Args);



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


[clang] c118339 - [clang] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-10-30 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-10-30T16:51:55-05:00
New Revision: c1183399a8205f83a418f20889776589b3b98d53

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

LOG: [clang] Remove no-op ptr-to-ptr bitcasts (NFC)

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CoverageMappingGen.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index c1be7c2d0321589..bcd67b7205c7dd2 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1809,7 +1809,7 @@ bool 
CGOpenMPRuntime::emitDeclareTargetVarDefinition(const VarDecl *VD,
/*IsInitializer=*/true);
   CtorCGF.FinishFunction();
   Ctor = Fn;
-  ID = llvm::ConstantExpr::getBitCast(Fn, CGM.Int8PtrTy);
+  ID = Fn;
 } else {
   Ctor = new llvm::GlobalVariable(
   CGM.getModule(), CGM.Int8Ty, /*isConstant=*/true,
@@ -1858,7 +1858,7 @@ bool 
CGOpenMPRuntime::emitDeclareTargetVarDefinition(const VarDecl *VD,
   DtorCGF.needsEHCleanup(ASTTy.isDestructedType()));
   DtorCGF.FinishFunction();
   Dtor = Fn;
-  ID = llvm::ConstantExpr::getBitCast(Fn, CGM.Int8PtrTy);
+  ID = Fn;
 } else {
   Dtor = new llvm::GlobalVariable(
   CGM.getModule(), CGM.Int8Ty, /*isConstant=*/true,

diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 76ed10091b025be..d77aa4dd78a06b3 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1728,13 +1728,11 @@ void 
CoverageMappingModuleGen::emitFunctionMappingRecord(
 void CoverageMappingModuleGen::addFunctionMappingRecord(
 llvm::GlobalVariable *NamePtr, StringRef NameValue, uint64_t FuncHash,
 const std::string &CoverageMapping, bool IsUsed) {
-  llvm::LLVMContext &Ctx = CGM.getLLVMContext();
   const uint64_t NameHash = llvm::IndexedInstrProf::ComputeHash(NameValue);
   FunctionRecords.push_back({NameHash, FuncHash, CoverageMapping, IsUsed});
 
   if (!IsUsed)
-FunctionNames.push_back(
-llvm::ConstantExpr::getBitCast(NamePtr, 
llvm::Type::getInt8PtrTy(Ctx)));
+FunctionNames.push_back(NamePtr);
 
   if (CGM.getCodeGenOpts().DumpCoverageMapping) {
 // Dump the coverage mapping data for this function by decoding the

diff  --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 0c89871420bdd3d..7877235a63356fc 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1324,7 +1324,6 @@ void ItaniumCXXABI::emitThrow(CodeGenFunction &CGF, const 
CXXThrowExpr *E) {
 if (!Record->hasTrivialDestructor()) {
   CXXDestructorDecl *DtorD = Record->getDestructor();
   Dtor = CGM.getAddrOfCXXStructor(GlobalDecl(DtorD, Dtor_Complete));
-  Dtor = llvm::ConstantExpr::getBitCast(Dtor, CGM.Int8PtrTy);
 }
   }
   if (!Dtor) Dtor = llvm::Constant::getNullValue(CGM.Int8PtrTy);



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


[clang] bc44e6e - [clang] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-11-01 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-01T09:06:15-05:00
New Revision: bc44e6e7c64ae7abd885fc31a62e37f649e307be

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

LOG: [clang] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque pointer cleanup effort.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CodeGenPGO.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7c2911468cad5f7..e047d31c012116f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5049,7 +5049,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__GetExceptionInfo: {
 if (llvm::GlobalVariable *GV =
 CGM.getCXXABI().getThrowInfo(FD->getParamDecl(0)->getType()))
-  return RValue::get(llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy));
+  return RValue::get(GV);
 break;
   }
 

diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 9e4319d27858e6f..0420f438ec1392c 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -386,9 +386,7 @@ CodeGenFunction::AddInitializerToStaticVarDecl(const 
VarDecl &D,
 GV->takeName(OldGV);
 
 // Replace all uses of the old global with the new global
-llvm::Constant *NewPtrForOldDecl =
-llvm::ConstantExpr::getBitCast(GV, OldGV->getType());
-OldGV->replaceAllUsesWith(NewPtrForOldDecl);
+OldGV->replaceAllUsesWith(GV);
 
 // Erase the old global, since it is no longer used.
 OldGV->eraseFromParent();

diff  --git a/clang/lib/CodeGen/CodeGenPGO.cpp 
b/clang/lib/CodeGen/CodeGenPGO.cpp
index 63cdd0a047bcd84..7d6c69f22d0e562 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -960,9 +960,8 @@ void CodeGenPGO::emitCounterIncrement(CGBuilderTy &Builder, 
const Stmt *S,
 return;
 
   unsigned Counter = (*RegionCounterMap)[S];
-  auto *I8PtrTy = llvm::Type::getInt8PtrTy(CGM.getLLVMContext());
 
-  llvm::Value *Args[] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
+  llvm::Value *Args[] = {FuncNameVar,
  Builder.getInt64(FunctionHash),
  Builder.getInt32(NumRegionCounters),
  Builder.getInt32(Counter), StepV};
@@ -1000,7 +999,7 @@ void CodeGenPGO::valueProfile(CGBuilderTy &Builder, 
uint32_t ValueKind,
 auto BuilderInsertPoint = Builder.saveIP();
 Builder.SetInsertPoint(ValueSite);
 llvm::Value *Args[5] = {
-llvm::ConstantExpr::getBitCast(FuncNameVar, Builder.getInt8PtrTy()),
+FuncNameVar,
 Builder.getInt64(FunctionHash),
 Builder.CreatePtrToInt(ValuePtr, Builder.getInt64Ty()),
 Builder.getInt32(ValueKind),

diff  --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 7877235a63356fc..c7295b3144ed16e 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -3938,9 +3938,7 @@ llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo(
   // If there's already an old global variable, replace it with the new one.
   if (OldGV) {
 GV->takeName(OldGV);
-llvm::Constant *NewPtr =
-  llvm::ConstantExpr::getBitCast(GV, OldGV->getType());
-OldGV->replaceAllUsesWith(NewPtr);
+OldGV->replaceAllUsesWith(GV);
 OldGV->eraseFromParent();
   }
 



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


[clang] 09f1aac - [CGBlocks] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-11-01 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-01T15:01:55-05:00
New Revision: 09f1aaca0bdc260c29043188aa2f63bcbe07f02f

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

LOG: [CGBlocks] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque ptr cleanup effort. NFC.

Added: 


Modified: 
clang/lib/CodeGen/CGBlocks.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 27f525ee35edbf9..dbc4cffa8976d6f 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -203,8 +203,7 @@ static llvm::Constant *buildBlockDescriptor(CodeGenModule 
&CGM,
   // Signature.  Mandatory ObjC-style method descriptor @encode sequence.
   std::string typeAtEncoding =
 CGM.getContext().getObjCEncodingForBlock(blockInfo.getBlockExpr());
-  elements.add(llvm::ConstantExpr::getBitCast(
-CGM.GetAddrOfConstantCString(typeAtEncoding).getPointer(), i8p));
+  elements.add(CGM.GetAddrOfConstantCString(typeAtEncoding).getPointer());
 
   // GC layout.
   if (C.getLangOpts().ObjC) {
@@ -809,7 +808,7 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const 
CGBlockInfo &blockInfo) {
 llvm::Constant *blockISA = blockInfo.NoEscape
? CGM.getNSConcreteGlobalBlock()
: CGM.getNSConcreteStackBlock();
-isa = llvm::ConstantExpr::getBitCast(blockISA, VoidPtrTy);
+isa = blockISA;
 
 // Build the block descriptor.
 descriptor = buildBlockDescriptor(CGM, blockInfo);
@@ -1869,7 +1868,7 @@ CodeGenFunction::GenerateCopyHelperFunction(const 
CGBlockInfo &blockInfo) {
   CaptureStrKind::CopyHelper, CGM);
 
   if (llvm::GlobalValue *Func = CGM.getModule().getNamedValue(FuncName))
-return llvm::ConstantExpr::getBitCast(Func, VoidPtrTy);
+return Func;
 
   ASTContext &C = getContext();
 
@@ -1990,7 +1989,7 @@ CodeGenFunction::GenerateCopyHelperFunction(const 
CGBlockInfo &blockInfo) {
 
   FinishFunction();
 
-  return llvm::ConstantExpr::getBitCast(Fn, VoidPtrTy);
+  return Fn;
 }
 
 static BlockFieldFlags
@@ -2056,7 +2055,7 @@ CodeGenFunction::GenerateDestroyHelperFunction(const 
CGBlockInfo &blockInfo) {
   CaptureStrKind::DisposeHelper, CGM);
 
   if (llvm::GlobalValue *Func = CGM.getModule().getNamedValue(FuncName))
-return llvm::ConstantExpr::getBitCast(Func, VoidPtrTy);
+return Func;
 
   ASTContext &C = getContext();
 
@@ -2113,7 +2112,7 @@ CodeGenFunction::GenerateDestroyHelperFunction(const 
CGBlockInfo &blockInfo) {
 
   FinishFunction();
 
-  return llvm::ConstantExpr::getBitCast(Fn, VoidPtrTy);
+  return Fn;
 }
 
 namespace {
@@ -2352,7 +2351,7 @@ generateByrefCopyHelper(CodeGenFunction &CGF, const 
BlockByrefInfo &byrefInfo,
 
   CGF.FinishFunction();
 
-  return llvm::ConstantExpr::getBitCast(Fn, CGF.Int8PtrTy);
+  return Fn;
 }
 
 /// Build the copy helper for a __block variable.
@@ -2408,7 +2407,7 @@ generateByrefDisposeHelper(CodeGenFunction &CGF,
 
   CGF.FinishFunction();
 
-  return llvm::ConstantExpr::getBitCast(Fn, CGF.Int8PtrTy);
+  return Fn;
 }
 
 /// Build the dispose helper for a __block variable.



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


[llvm] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-02 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

I have a similar concern with @arsenm about making the default address space 0.
Can't we just use the already existing `PointerType::getUnqual()`, instead of 
introducing the default address space 0?

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


[clang] 5532d67 - [clang] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-11-02 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-02T12:43:26-05:00
New Revision: 5532d67a360e99f6b60d311d64e94a5a32d5d141

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

LOG: [clang] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque ptr cleanup effort (NFC)

Added: 


Modified: 
clang/lib/CodeGen/CGBlocks.cpp
clang/lib/CodeGen/CGDeclCXX.cpp
clang/lib/CodeGen/CGExprConstant.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index dbc4cffa8976d6f..4f3a6e34bda2fe1 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -164,8 +164,7 @@ static llvm::Constant *buildBlockDescriptor(CodeGenModule 
&CGM,
   CGM.getLangOpts().getGC() == LangOptions::NonGC) {
 descName = getBlockDescriptorName(blockInfo, CGM);
 if (llvm::GlobalValue *desc = CGM.getModule().getNamedValue(descName))
-  return llvm::ConstantExpr::getBitCast(desc,
-CGM.getBlockDescriptorType());
+  return desc;
   }
 
   // If there isn't an equivalent block descriptor global variable, create a 
new
@@ -242,7 +241,7 @@ static llvm::Constant *buildBlockDescriptor(CodeGenModule 
&CGM,
 global->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
   }
 
-  return llvm::ConstantExpr::getBitCast(global, CGM.getBlockDescriptorType());
+  return global;
 }
 
 /*

diff  --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index e10617162733bba..93742688fb9cbdd 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -126,7 +126,7 @@ static void EmitDeclDestroy(CodeGenFunction &CGF, const 
VarDecl &D,
   CGM.getLLVMContext(), 
CGM.getContext().getTargetAddressSpace(DestAS));
   auto SrcAS = D.getType().getQualifiers().getAddressSpace();
   if (DestAS == SrcAS)
-Argument = llvm::ConstantExpr::getBitCast(Addr.getPointer(), DestTy);
+Argument = Addr.getPointer();
   else
 // FIXME: On addr space mismatch we are passing NULL. The generation
 // of the global destructor function should be adjusted accordingly.
@@ -167,8 +167,7 @@ void CodeGenFunction::EmitInvariantStart(llvm::Constant 
*Addr, CharUnits Size) {
 
   // Emit a call with the size in bytes of the object.
   uint64_t Width = Size.getQuantity();
-  llvm::Value *Args[2] = { llvm::ConstantInt::getSigned(Int64Ty, Width),
-   llvm::ConstantExpr::getBitCast(Addr, Int8PtrTy)};
+  llvm::Value *Args[2] = {llvm::ConstantInt::getSigned(Int64Ty, Width), Addr};
   Builder.CreateCall(InvariantStart, Args);
 }
 

diff  --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index cd91a698a9336f8..69616dcc07efe1f 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -1630,13 +1630,8 @@ namespace {
 IndexValues[i] = llvm::ConstantInt::get(CGM.Int32Ty, Indices[i]);
   }
 
-  // Form a GEP and then bitcast to the placeholder type so that the
-  // replacement will succeed.
-  llvm::Constant *location =
-llvm::ConstantExpr::getInBoundsGetElementPtr(BaseValueTy,
- Base, IndexValues);
-  location = llvm::ConstantExpr::getBitCast(location,
-placeholder->getType());
+  llvm::Constant *location = llvm::ConstantExpr::getInBoundsGetElementPtr(
+  BaseValueTy, Base, IndexValues);
 
   Locations.insert({placeholder, location});
 }
@@ -2037,8 +2032,6 @@ ConstantLValue
 ConstantLValueEmitter::VisitAddrLabelExpr(const AddrLabelExpr *E) {
   assert(Emitter.CGF && "Invalid address of label expression outside 
function");
   llvm::Constant *Ptr = Emitter.CGF->GetAddrOfLabel(E->getLabel());
-  Ptr = llvm::ConstantExpr::getBitCast(Ptr,
-   CGM.getTypes().ConvertType(E->getType()));
   return Ptr;
 }
 



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


[clang] 14f2025 - [clang][CGExpr] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-11-02 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-02T17:50:46-05:00
New Revision: 14f2025671f82192d38e1db9bc185790e1221cd3

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

LOG: [clang][CGExpr] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque ptr cleanup effort.

Added: 


Modified: 
clang/lib/CodeGen/CGExpr.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 54a1d300a9ac738..46d0b5b8c277f00 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -450,9 +450,7 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr 
*M) {
 Address Object = createReferenceTemporary(*this, M, E);
 if (auto *Var = dyn_cast(Object.getPointer())) {
   llvm::Type *Ty = ConvertTypeForMem(E->getType());
-  Object = Address(llvm::ConstantExpr::getBitCast(
-   Var, Ty->getPointerTo(Object.getAddressSpace())),
-   Ty, Object.getAlignment());
+  Object = Object.withElementType(Ty);
 
   // createReferenceTemporary will promote the temporary to a global with a
   // constant initializer if it can.  It can only do this to a value of
@@ -508,11 +506,7 @@ EmitMaterializeTemporaryExpr(const 
MaterializeTemporaryExpr *M) {
   if (auto *Var = dyn_cast(
   Object.getPointer()->stripPointerCasts())) {
 llvm::Type *TemporaryType = ConvertTypeForMem(E->getType());
-Object = Address(llvm::ConstantExpr::getBitCast(
- cast(Object.getPointer()),
- TemporaryType->getPointerTo()),
- TemporaryType,
- Object.getAlignment());
+Object = Object.withElementType(TemporaryType);
 // If the temporary is a global and has a constant initializer or is a
 // constant temporary that we promoted to a global, we may have already
 // initialized it.
@@ -2678,19 +2672,6 @@ static llvm::Constant 
*EmitFunctionDeclPointer(CodeGenModule &CGM,
   }
 
   llvm::Constant *V = CGM.GetAddrOfFunction(GD);
-  if (!FD->hasPrototype()) {
-if (const FunctionProtoType *Proto =
-FD->getType()->getAs()) {
-  // Ugly case: for a K&R-style definition, the type of the definition
-  // isn't the same as the type of a use.  Correct for this with a
-  // bitcast.
-  QualType NoProtoType =
-  CGM.getContext().getFunctionNoProtoType(Proto->getReturnType());
-  NoProtoType = CGM.getContext().getPointerType(NoProtoType);
-  V = llvm::ConstantExpr::getBitCast(V,
-  CGM.getTypes().ConvertType(NoProtoType));
-}
-  }
   return V;
 }
 



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


[llvm] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-03 Thread Youngsuk Kim via cfe-commits

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


[llvm] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-03 Thread Youngsuk Kim via cfe-commits


@@ -1514,7 +1514,7 @@ static void CreateGCRelocates(ArrayRef 
LiveVariables,
   auto getGCRelocateDecl = [&](Type *Ty) {
 assert(isHandledGCPointerType(Ty, GC));
 auto AS = Ty->getScalarType()->getPointerAddressSpace();
-Type *NewTy = Type::getInt8PtrTy(M->getContext(), AS);
+Type *NewTy = PointerType::getUnqual(M->getContext(), AS);

JOE1994 wrote:

Thank you for the update 👍 

The following update is needed to avoid build failure.
```suggestion
Type *NewTy = PointerType::get(M->getContext(), AS);
```

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


[clang] fc55068 - [clang][MicrosoftCXXABI] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-11-03 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-03T17:05:44-05:00
New Revision: fc55068c0969fa83d894d46e14d4fdec05a30b2c

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

LOG: [clang][MicrosoftCXXABI] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque ptr cleanup effort (NFC)

Added: 


Modified: 
clang/lib/CodeGen/MicrosoftCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 4e55d6be376a517..1f0e6c1be705525 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -2986,7 +2986,6 @@ MicrosoftCXXABI::EmitMemberFunctionPointer(const 
CXXMethodDecl *MD) {
 NonVirtualBaseAdjustment -= getContext().getOffsetOfBaseWithVBPtr(RD);
 
   // The rest of the fields are common with data member pointers.
-  FirstField = llvm::ConstantExpr::getBitCast(FirstField, CGM.VoidPtrTy);
   return EmitFullMemberPointer(FirstField, /*IsMemberFunction=*/true, RD,
NonVirtualBaseAdjustment, VBTableIndex);
 }
@@ -3981,7 +3980,7 @@ llvm::Constant 
*MicrosoftCXXABI::getAddrOfRTTIDescriptor(QualType Type) {
 
   // Check to see if we've already declared this TypeDescriptor.
   if (llvm::GlobalVariable *GV = CGM.getModule().getNamedGlobal(MangledName))
-return llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy);
+return GV;
 
   // Note for the future: If we would ever like to do deferred emission of
   // RTTI, check if emitting vtables opportunistically need any adjustment.
@@ -4007,7 +4006,7 @@ llvm::Constant 
*MicrosoftCXXABI::getAddrOfRTTIDescriptor(QualType Type) {
   MangledName);
   if (Var->isWeakForLinker())
 Var->setComdat(CGM.getModule().getOrInsertComdat(Var->getName()));
-  return llvm::ConstantExpr::getBitCast(Var, CGM.Int8PtrTy);
+  return Var;
 }
 
 /// Gets or a creates a Microsoft CompleteObjectLocator.
@@ -4200,8 +4199,6 @@ llvm::Constant 
*MicrosoftCXXABI::getCatchableType(QualType T,
   CopyCtor = getAddrOfCXXCtorClosure(CD, Ctor_CopyingClosure);
 else
   CopyCtor = CGM.getAddrOfCXXStructor(GlobalDecl(CD, Ctor_Complete));
-
-CopyCtor = llvm::ConstantExpr::getBitCast(CopyCtor, CGM.Int8PtrTy);
   } else {
 CopyCtor = llvm::Constant::getNullValue(CGM.Int8PtrTy);
   }
@@ -4411,14 +4408,11 @@ llvm::GlobalVariable 
*MicrosoftCXXABI::getThrowInfo(QualType T) {
   if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl())
 if (CXXDestructorDecl *DtorD = RD->getDestructor())
   if (!DtorD->isTrivial())
-CleanupFn = llvm::ConstantExpr::getBitCast(
-CGM.getAddrOfCXXStructor(GlobalDecl(DtorD, Dtor_Complete)),
-CGM.Int8PtrTy);
+CleanupFn = CGM.getAddrOfCXXStructor(GlobalDecl(DtorD, Dtor_Complete));
   // This is unused as far as we can tell, initialize it to null.
   llvm::Constant *ForwardCompat =
   getImageRelativeConstant(llvm::Constant::getNullValue(CGM.Int8PtrTy));
-  llvm::Constant *PointerToCatchableTypes = getImageRelativeConstant(
-  llvm::ConstantExpr::getBitCast(CTA, CGM.Int8PtrTy));
+  llvm::Constant *PointerToCatchableTypes = getImageRelativeConstant(CTA);
   llvm::StructType *TIType = getThrowInfoType();
   llvm::Constant *Fields[] = {
   llvm::ConstantInt::get(CGM.IntTy, Flags), // Flags



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


[clang] 9e90027 - [CGException] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-11-04 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-04T19:17:21-05:00
New Revision: 9e90027d618687f3d744e21ad3eda5735a167503

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

LOG: [CGException] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque ptr cleanup effort (NFC).

Added: 


Modified: 
clang/lib/CodeGen/CGException.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 87594f71b26ec53..4a54b2040154dad 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -263,12 +263,7 @@ static llvm::FunctionCallee getPersonalityFn(CodeGenModule 
&CGM,
 static llvm::Constant *getOpaquePersonalityFn(CodeGenModule &CGM,
 const EHPersonality &Personality) {
   llvm::FunctionCallee Fn = getPersonalityFn(CGM, Personality);
-  llvm::PointerType* Int8PtrTy = llvm::PointerType::get(
-  llvm::Type::getInt8Ty(CGM.getLLVMContext()),
-  CGM.getDataLayout().getProgramAddressSpace());
-
-  return llvm::ConstantExpr::getBitCast(cast(Fn.getCallee()),
-Int8PtrTy);
+  return cast(Fn.getCallee());
 }
 
 /// Check whether a landingpad instruction only uses C++ features.
@@ -1838,13 +1833,11 @@ Address 
CodeGenFunction::recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF,
 auto InsertPair = ParentCGF.EscapedLocals.insert(
 std::make_pair(ParentAlloca, ParentCGF.EscapedLocals.size()));
 int FrameEscapeIdx = InsertPair.first->second;
-// call i8* @llvm.localrecover(i8* bitcast(@parentFn), i8* %fp, i32 N)
+// call ptr @llvm.localrecover(ptr @parentFn, ptr %fp, i32 N)
 llvm::Function *FrameRecoverFn = llvm::Intrinsic::getDeclaration(
 &CGM.getModule(), llvm::Intrinsic::localrecover);
-llvm::Constant *ParentI8Fn =
-llvm::ConstantExpr::getBitCast(ParentCGF.CurFn, Int8PtrTy);
 RecoverCall = Builder.CreateCall(
-FrameRecoverFn, {ParentI8Fn, ParentFP,
+FrameRecoverFn, {ParentCGF.CurFn, ParentFP,
  llvm::ConstantInt::get(Int32Ty, FrameEscapeIdx)});
 
   } else {
@@ -1907,9 +1900,7 @@ void CodeGenFunction::EmitCapturedLocals(CodeGenFunction 
&ParentCGF,
 // since finally funclets recover the parent FP for us.
 llvm::Function *RecoverFPIntrin =
 CGM.getIntrinsic(llvm::Intrinsic::eh_recoverfp);
-llvm::Constant *ParentI8Fn =
-llvm::ConstantExpr::getBitCast(ParentCGF.CurFn, Int8PtrTy);
-ParentFP = Builder.CreateCall(RecoverFPIntrin, {ParentI8Fn, EntryFP});
+ParentFP = Builder.CreateCall(RecoverFPIntrin, {ParentCGF.CurFn, EntryFP});
 
 // if the parent is a _finally, the passed-in ParentFP is the FP
 // of parent _finally, not Establisher's FP (FP of outermost function).
@@ -1937,19 +1928,15 @@ void 
CodeGenFunction::EmitCapturedLocals(CodeGenFunction &ParentCGF,
   int FrameEscapeIdx = InsertPair.first->second;
 
   // an example of a filter's prolog::
-  // %0 = call i8* @llvm.eh.recoverfp(bitcast(@"?fin$0@0@main@@"),..)
-  // %1 = call i8* @llvm.localrecover(bitcast(@"?fin$0@0@main@@"),..)
-  // %2 = bitcast i8* %1 to i8**
-  // %3 = load i8*, i8* *%2, align 8
-  //   ==> %3 is the frame-pointer of outermost host function
+  // %0 = call ptr @llvm.eh.recoverfp(@"?fin$0@0@main@@",..)
+  // %1 = call ptr @llvm.localrecover(@"?fin$0@0@main@@",..)
+  // %2 = load ptr, ptr %1, align 8
+  //   ==> %2 is the frame-pointer of outermost host function
   llvm::Function *FrameRecoverFn = llvm::Intrinsic::getDeclaration(
   &CGM.getModule(), llvm::Intrinsic::localrecover);
-  llvm::Constant *ParentI8Fn =
-  llvm::ConstantExpr::getBitCast(ParentCGF.CurFn, Int8PtrTy);
   ParentFP = Builder.CreateCall(
-  FrameRecoverFn, {ParentI8Fn, ParentFP,
+  FrameRecoverFn, {ParentCGF.CurFn, ParentFP,
llvm::ConstantInt::get(Int32Ty, FrameEscapeIdx)});
-  ParentFP = Builder.CreateBitCast(ParentFP, CGM.VoidPtrPtrTy);
   ParentFP = Builder.CreateLoad(
   Address(ParentFP, CGM.VoidPtrTy, getPointerAlign()));
 }
@@ -2206,9 +2193,7 @@ void CodeGenFunction::EnterSEHTryStmt(const SEHTryStmt 
&S) {
   // in place of the RTTI typeinfo global that C++ EH uses.
   llvm::Function *FilterFunc =
   HelperCGF.GenerateSEHFilterFunction(*this, *Except);
-  llvm::Constant *OpaqueFunc =
-  llvm::ConstantExpr::getBitCast(FilterFunc, Int8PtrTy);
-  CatchScope->setHandler(0, OpaqueFunc, createBasicBlock("__except.ret"));
+  CatchScope->setHandler(0, FilterFunc, createBasicBlock("__except.ret"));
 }
 
 void CodeGenFunction::ExitSEHTryStmt(const SEHTryStmt &S) {



___
cfe-commits mailing l

[clang] 730d313 - [CGObjC] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-11-04 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-04T19:59:39-05:00
New Revision: 730d313041f73760aacc3fa3b12b5b5b0c92a12c

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

LOG: [CGObjC] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque ptr cleanup effort (NFC)

Added: 


Modified: 
clang/lib/CodeGen/CGObjC.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 5c967f97018f800..fff89c8939a55a4 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -52,8 +52,7 @@ llvm::Value *CodeGenFunction::EmitObjCStringLiteral(const 
ObjCStringLiteral *E)
 {
   llvm::Constant *C =
   CGM.getObjCRuntime().GenerateConstantString(E->getString()).getPointer();
-  // FIXME: This bitcast should just be made an invariant on the Runtime.
-  return llvm::ConstantExpr::getBitCast(C, ConvertType(E->getType()));
+  return C;
 }
 
 /// EmitObjCBoxedExpr - This routine generates code to call
@@ -3710,7 +3709,7 @@ 
CodeGenFunction::GenerateObjCAtomicSetterCopyHelperFunction(
 CharUnits Alignment = C.getTypeAlignInChars(Ty);
 llvm::Constant *Fn = getNonTrivialCStructMoveAssignmentOperator(
 CGM, Alignment, Alignment, Ty.isVolatileQualified(), Ty);
-return llvm::ConstantExpr::getBitCast(Fn, VoidPtrTy);
+return Fn;
   }
 
   if (!getLangOpts().CPlusPlus ||
@@ -3790,7 +3789,7 @@ 
CodeGenFunction::GenerateObjCAtomicSetterCopyHelperFunction(
   EmitStmt(TheCall);
 
   FinishFunction();
-  HelperFn = llvm::ConstantExpr::getBitCast(Fn, VoidPtrTy);
+  HelperFn = Fn;
   CGM.setAtomicSetterHelperFnMap(Ty, HelperFn);
   return HelperFn;
 }
@@ -3808,7 +3807,7 @@ llvm::Constant 
*CodeGenFunction::GenerateObjCAtomicGetterCopyHelperFunction(
 CharUnits Alignment = C.getTypeAlignInChars(Ty);
 llvm::Constant *Fn = getNonTrivialCStructCopyConstructor(
 CGM, Alignment, Alignment, Ty.isVolatileQualified(), Ty);
-return llvm::ConstantExpr::getBitCast(Fn, VoidPtrTy);
+return Fn;
   }
 
   if (!getLangOpts().CPlusPlus ||
@@ -3909,7 +3908,7 @@ llvm::Constant 
*CodeGenFunction::GenerateObjCAtomicGetterCopyHelperFunction(
   AggValueSlot::IsNotAliased, AggValueSlot::DoesNotOverlap));
 
   FinishFunction();
-  HelperFn = llvm::ConstantExpr::getBitCast(Fn, VoidPtrTy);
+  HelperFn = Fn;
   CGM.setAtomicGetterHelperFnMap(Ty, HelperFn);
   return HelperFn;
 }



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


[clang] b26b1ce - [clang][CodeGenModule] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-11-05 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-05T10:17:45-06:00
New Revision: b26b1cee2e6b0b730fda87dbd4a236810d424129

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

LOG: [clang][CodeGenModule] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque ptr cleanup effort (NFC).

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 35f651b39f6748a..f72101799d31e4c 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3201,10 +3201,9 @@ llvm::Constant *CodeGenModule::EmitAnnotationArgs(const 
AnnotateAttr *Attr) {
   ".args");
   GV->setSection(AnnotationSection);
   GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
-  auto *Bitcasted = llvm::ConstantExpr::getBitCast(GV, GlobalsInt8PtrTy);
 
-  Lookup = Bitcasted;
-  return Bitcasted;
+  Lookup = GV;
+  return GV;
 }
 
 llvm::Constant *CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV,
@@ -3227,11 +3226,7 @@ llvm::Constant 
*CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV,
 
   // Create the ConstantStruct for the global annotation.
   llvm::Constant *Fields[] = {
-  llvm::ConstantExpr::getBitCast(GVInGlobalsAS, GlobalsInt8PtrTy),
-  llvm::ConstantExpr::getBitCast(AnnoGV, ConstGlobalsPtrTy),
-  llvm::ConstantExpr::getBitCast(UnitGV, ConstGlobalsPtrTy),
-  LineNoCst,
-  Args,
+  GVInGlobalsAS, AnnoGV, UnitGV, LineNoCst, Args,
   };
   return llvm::ConstantStruct::getAnon(Fields);
 }
@@ -4697,9 +4692,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef 
MangledName, llvm::Type *Ty,
 GV->takeName(Entry);
 
 if (!Entry->use_empty()) {
-  llvm::Constant *NewPtrForOldDecl =
-  llvm::ConstantExpr::getBitCast(GV, Entry->getType());
-  Entry->replaceAllUsesWith(NewPtrForOldDecl);
+  Entry->replaceAllUsesWith(GV);
 }
 
 Entry->eraseFromParent();
@@ -4878,9 +4871,7 @@ llvm::GlobalVariable 
*CodeGenModule::CreateOrReplaceCXXRuntimeVariable(
 GV->takeName(OldGV);
 
 if (!OldGV->use_empty()) {
-  llvm::Constant *NewPtrForOldDecl =
-  llvm::ConstantExpr::getBitCast(GV, OldGV->getType());
-  OldGV->replaceAllUsesWith(NewPtrForOldDecl);
+  OldGV->replaceAllUsesWith(GV);
 }
 
 OldGV->eraseFromParent();
@@ -5766,8 +5757,7 @@ void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) {
 // Remove it and replace uses of it with the alias.
 GA->takeName(Entry);
 
-Entry->replaceAllUsesWith(llvm::ConstantExpr::getBitCast(GA,
-  Entry->getType()));
+Entry->replaceAllUsesWith(GA);
 Entry->eraseFromParent();
   } else {
 GA->setName(MangledName);
@@ -5845,8 +5835,7 @@ void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
 // Remove it and replace uses of it with the ifunc.
 GIF->takeName(Entry);
 
-Entry->replaceAllUsesWith(llvm::ConstantExpr::getBitCast(GIF,
-  Entry->getType()));
+Entry->replaceAllUsesWith(GIF);
 Entry->eraseFromParent();
   } else
 GIF->setName(MangledName);
@@ -6042,9 +6031,6 @@ CodeGenModule::GetAddrOfConstantCFString(const 
StringLiteral *Literal) {
   llvm::Constant *Str =
   llvm::ConstantExpr::getGetElementPtr(GV->getValueType(), GV, Zeros);
 
-  if (isUTF16)
-// Cast the UTF16 string to the correct type.
-Str = llvm::ConstantExpr::getBitCast(Str, Int8PtrTy);
   Fields.add(Str);
 
   // String length.
@@ -6414,8 +6400,7 @@ ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary(
   // replace it with the new global now.
   llvm::Constant *&Entry = MaterializedGlobalTemporaryMap[E];
   if (Entry) {
-Entry->replaceAllUsesWith(
-llvm::ConstantExpr::getBitCast(CV, Entry->getType()));
+Entry->replaceAllUsesWith(CV);
 llvm::cast(Entry)->eraseFromParent();
   }
   Entry = CV;



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


[clang-tools-extra] [mlir] [flang] [clang] [libcxx] [compiler-rt] [llvm] [libc] [mlir][spirv] Implement gpu::TargetAttrInterface (PR #69949)

2023-11-05 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

This revision seems related to the following buildbot failure:

* https://lab.llvm.org/buildbot/#/builders/268/builds/1747
  (+ builds 1748 & 1749) 

Would you mind taking a look? Thank you 👍 

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


[clang] [clang][CGCUDANV] Unify PointerType members of CGNVCUDARuntime (NFC) (PR #75668)

2023-12-15 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 created 
https://github.com/llvm/llvm-project/pull/75668

Unify 3 `Pointertype *` members which all refer to the same llvm type.

Opaque pointer clean-up effort.

>From 2f07997d202a8e845e866d0dedbfbcded0bf9518 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Fri, 15 Dec 2023 16:50:02 -0600
Subject: [PATCH] [clang][CGCUDANV] Unify PointerType members of
 CGNVCUDARuntime (NFC)

Unify 3 `Pointertype *` members which all refer to the same llvm type.

Opaque pointer clean-up effort.
---
 clang/lib/CodeGen/CGCUDANV.cpp | 88 +++---
 1 file changed, 38 insertions(+), 50 deletions(-)

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 520b0c4f117673..353370f1d761b9 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -39,7 +39,7 @@ class CGNVCUDARuntime : public CGCUDARuntime {
 private:
   llvm::IntegerType *IntTy, *SizeTy;
   llvm::Type *VoidTy;
-  llvm::PointerType *CharPtrTy, *VoidPtrTy, *VoidPtrPtrTy;
+  llvm::PointerType *PtrTy;
 
   /// Convenience reference to LLVM Context
   llvm::LLVMContext &Context;
@@ -232,15 +232,12 @@ CGNVCUDARuntime::CGNVCUDARuntime(CodeGenModule &CGM)
   VoidTy = CGM.VoidTy;
   Zeros[0] = llvm::ConstantInt::get(SizeTy, 0);
   Zeros[1] = Zeros[0];
-
-  CharPtrTy = CGM.UnqualPtrTy;
-  VoidPtrTy = CGM.UnqualPtrTy;
-  VoidPtrPtrTy = CGM.UnqualPtrTy;
+  PtrTy = CGM.UnqualPtrTy;
 }
 
 llvm::FunctionCallee CGNVCUDARuntime::getSetupArgumentFn() const {
   // cudaError_t cudaSetupArgument(void *, size_t, size_t)
-  llvm::Type *Params[] = {VoidPtrTy, SizeTy, SizeTy};
+  llvm::Type *Params[] = {PtrTy, SizeTy, SizeTy};
   return CGM.CreateRuntimeFunction(
   llvm::FunctionType::get(IntTy, Params, false),
   addPrefixToName("SetupArgument"));
@@ -250,24 +247,24 @@ llvm::FunctionCallee CGNVCUDARuntime::getLaunchFn() const 
{
   if (CGM.getLangOpts().HIP) {
 // hipError_t hipLaunchByPtr(char *);
 return CGM.CreateRuntimeFunction(
-llvm::FunctionType::get(IntTy, CharPtrTy, false), "hipLaunchByPtr");
+llvm::FunctionType::get(IntTy, PtrTy, false), "hipLaunchByPtr");
   }
   // cudaError_t cudaLaunch(char *);
-  return CGM.CreateRuntimeFunction(
-  llvm::FunctionType::get(IntTy, CharPtrTy, false), "cudaLaunch");
+  return CGM.CreateRuntimeFunction(llvm::FunctionType::get(IntTy, PtrTy, 
false),
+   "cudaLaunch");
 }
 
 llvm::FunctionType *CGNVCUDARuntime::getRegisterGlobalsFnTy() const {
-  return llvm::FunctionType::get(VoidTy, VoidPtrPtrTy, false);
+  return llvm::FunctionType::get(VoidTy, PtrTy, false);
 }
 
 llvm::FunctionType *CGNVCUDARuntime::getCallbackFnTy() const {
-  return llvm::FunctionType::get(VoidTy, VoidPtrTy, false);
+  return llvm::FunctionType::get(VoidTy, PtrTy, false);
 }
 
 llvm::FunctionType *CGNVCUDARuntime::getRegisterLinkedBinaryFnTy() const {
-  llvm::Type *Params[] = {llvm::PointerType::getUnqual(Context), VoidPtrTy,
-  VoidPtrTy, llvm::PointerType::getUnqual(Context)};
+  llvm::Type *Params[] = {llvm::PointerType::getUnqual(Context), PtrTy, PtrTy,
+  llvm::PointerType::getUnqual(Context)};
   return llvm::FunctionType::get(VoidTy, Params, false);
 }
 
@@ -330,15 +327,15 @@ void 
CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction &CGF,
   // args, allocate a single pointer so we still have a valid pointer to the
   // argument array that we can pass to runtime, even if it will be unused.
   Address KernelArgs = CGF.CreateTempAlloca(
-  VoidPtrTy, CharUnits::fromQuantity(16), "kernel_args",
+  PtrTy, CharUnits::fromQuantity(16), "kernel_args",
   llvm::ConstantInt::get(SizeTy, std::max(1, Args.size(;
   // Store pointers to the arguments in a locally allocated launch_args.
   for (unsigned i = 0; i < Args.size(); ++i) {
 llvm::Value* VarPtr = CGF.GetAddrOfLocalVar(Args[i]).getPointer();
-llvm::Value *VoidVarPtr = CGF.Builder.CreatePointerCast(VarPtr, VoidPtrTy);
+llvm::Value *VoidVarPtr = CGF.Builder.CreatePointerCast(VarPtr, PtrTy);
 CGF.Builder.CreateDefaultAlignedStore(
 VoidVarPtr,
-CGF.Builder.CreateConstGEP1_32(VoidPtrTy, KernelArgs.getPointer(), i));
+CGF.Builder.CreateConstGEP1_32(PtrTy, KernelArgs.getPointer(), i));
   }
 
   llvm::BasicBlock *EndBlock = CGF.createBasicBlock("setup.end");
@@ -386,8 +383,7 @@ void CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction 
&CGF,
   CGF.CreateMemTemp(Dim3Ty, CharUnits::fromQuantity(8), "block_dim");
   Address ShmemSize =
   CGF.CreateTempAlloca(SizeTy, CGM.getSizeAlign(), "shmem_size");
-  Address Stream =
-  CGF.CreateTempAlloca(VoidPtrTy, CGM.getPointerAlign(), "stream");
+  Address Stream = CGF.CreateTempAlloca(PtrTy, CGM.getPointerAlign(), 
"stream");
   llvm::FunctionCallee cudaPopConfigFn = CGM.CreateRuntimeFunction(
   llvm::FunctionType::get(IntTy,
   {/*gridDim=*/GridDim.getTyp

[clang] [clang][CGCUDANV] Unify PointerType members of CGNVCUDARuntime (NFC) (PR #75668)

2023-12-16 Thread Youngsuk Kim via cfe-commits

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


[clang] d8c4080 - [clang][CGExprConstant] Remove no-op ptr-to-ptr bitcast (NFC)

2023-11-23 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-23T09:17:01-06:00
New Revision: d8c40800edc5995c5ff765c4e2940ea001589fa0

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

LOG: [clang][CGExprConstant] Remove no-op ptr-to-ptr bitcast (NFC)

Remove a call to `getPointerCast` which is effectively does a no-op ptr-to-ptr
bitcast.

Opaque ptr clean-up effort.

Added: 


Modified: 
clang/lib/CodeGen/CGExprConstant.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index 69616dcc07efe1f..604e3958161db23 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -1861,10 +1861,7 @@ class ConstantLValueEmitter : public 
ConstStmtVisitorgetType();
-C = llvm::ConstantExpr::getGetElementPtr(CGM.Int8Ty, C, getOffset());
-C = llvm::ConstantExpr::getPointerCast(C, origPtrTy);
-return C;
+return llvm::ConstantExpr::getGetElementPtr(CGM.Int8Ty, C, getOffset());
   }
 };
 



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


[clang] [clang][CodeGen] Remove ptr-to-ptr bitcasts (NFC) (PR #73020)

2023-11-23 Thread Youngsuk Kim via cfe-commits

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


[clang] [clang] Avoid memcopy for small structure with padding under -ftrivial-auto-var-init (PR #71677)

2023-11-23 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

FYI, the following `clang` tests seem to fail after revision 
[fe5c360](https://github.com/llvm/llvm-project/commit/fe5c360a9aae61db37886c0c795c409b5129905f)
```
Failed Tests (2):
  Clang :: CodeGen/aapcs-align.cpp
  Clang :: CodeGen/aapcs64-align.cpp
```

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


[clang] [clang-linker-wrapper] Re-use type returned from 'PointerType::getUnqual(C)' (NFC) (PR #73374)

2023-11-24 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 created 
https://github.com/llvm/llvm-project/pull/73374

Multiple calls to `PointerType::getUnqual(C)`, and calls to 
`Type::getPointerTo(AddrSpace=0)` on them all result in the same type.

Clean them up to re-use the same `PtrTy` variable within function 
`createRegisterGlobalsFunction()`.

>From cd36ba2c52f14051cbe82efc6390a036f75d2b46 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Thu, 23 Nov 2023 10:54:07 -0600
Subject: [PATCH] [clang-linker-wrapper] Re-use type returned from
 'PointerType::getUnqual(C)' (NFC)

Multiple calls to `PointerType::getUnqual(C)`, and calls to
`Type::getPointerTo(AddrSpace=0)` on them all result in the same type.

Clean them up to re-use the same `PtrTy` variable within function
`createRegisterGlobalsFunction()`.
---
 .../clang-linker-wrapper/OffloadWrapper.cpp   | 34 ---
 1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp 
b/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp
index 4bbfba777e1854f..5daa7c083b564e0 100644
--- a/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp
@@ -445,6 +445,7 @@ Function *createRegisterGlobalsFunction(Module &M, bool 
IsHIP) {
 void createRegisterFatbinFunction(Module &M, GlobalVariable *FatbinDesc,
   bool IsHIP) {
   LLVMContext &C = M.getContext();
+  auto *PtrTy = PointerType::getUnqual(C);
   auto *CtorFuncTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg*/ false);
   auto *CtorFunc =
   Function::Create(CtorFuncTy, GlobalValue::InternalLinkage,
@@ -458,44 +459,39 @@ void createRegisterFatbinFunction(Module &M, 
GlobalVariable *FatbinDesc,
   DtorFunc->setSection(".text.startup");
 
   // Get the __cudaRegisterFatBinary function declaration.
-  auto *RegFatTy = FunctionType::get(PointerType::getUnqual(C)->getPointerTo(),
- PointerType::getUnqual(C),
+  auto *RegFatTy = FunctionType::get(PtrTy, PtrTy,
  /*isVarArg*/ false);
   FunctionCallee RegFatbin = M.getOrInsertFunction(
   IsHIP ? "__hipRegisterFatBinary" : "__cudaRegisterFatBinary", RegFatTy);
   // Get the __cudaRegisterFatBinaryEnd function declaration.
-  auto *RegFatEndTy = FunctionType::get(
-  Type::getVoidTy(C), PointerType::getUnqual(C)->getPointerTo(),
-  /*isVarArg*/ false);
+  auto *RegFatEndTy = FunctionType::get(Type::getVoidTy(C), PtrTy,
+/*isVarArg*/ false);
   FunctionCallee RegFatbinEnd =
   M.getOrInsertFunction("__cudaRegisterFatBinaryEnd", RegFatEndTy);
   // Get the __cudaUnregisterFatBinary function declaration.
-  auto *UnregFatTy = FunctionType::get(
-  Type::getVoidTy(C), PointerType::getUnqual(C)->getPointerTo(),
-  /*isVarArg*/ false);
+  auto *UnregFatTy = FunctionType::get(Type::getVoidTy(C), PtrTy,
+   /*isVarArg*/ false);
   FunctionCallee UnregFatbin = M.getOrInsertFunction(
   IsHIP ? "__hipUnregisterFatBinary" : "__cudaUnregisterFatBinary",
   UnregFatTy);
 
-  auto *AtExitTy =
-  FunctionType::get(Type::getInt32Ty(C), DtorFuncTy->getPointerTo(),
-/*isVarArg*/ false);
+  auto *AtExitTy = FunctionType::get(Type::getInt32Ty(C), PtrTy,
+ /*isVarArg*/ false);
   FunctionCallee AtExit = M.getOrInsertFunction("atexit", AtExitTy);
 
   auto *BinaryHandleGlobal = new llvm::GlobalVariable(
-  M, PointerType::getUnqual(C)->getPointerTo(), false,
-  llvm::GlobalValue::InternalLinkage,
-  
llvm::ConstantPointerNull::get(PointerType::getUnqual(C)->getPointerTo()),
+  M, PtrTy, false, llvm::GlobalValue::InternalLinkage,
+  llvm::ConstantPointerNull::get(PtrTy),
   IsHIP ? ".hip.binary_handle" : ".cuda.binary_handle");
 
   // Create the constructor to register this image with the runtime.
   IRBuilder<> CtorBuilder(BasicBlock::Create(C, "entry", CtorFunc));
   CallInst *Handle = CtorBuilder.CreateCall(
-  RegFatbin, ConstantExpr::getPointerBitCastOrAddrSpaceCast(
- FatbinDesc, PointerType::getUnqual(C)));
+  RegFatbin,
+  ConstantExpr::getPointerBitCastOrAddrSpaceCast(FatbinDesc, PtrTy));
   CtorBuilder.CreateAlignedStore(
   Handle, BinaryHandleGlobal,
-  Align(M.getDataLayout().getPointerTypeSize(PointerType::getUnqual(C;
+  Align(M.getDataLayout().getPointerTypeSize(PtrTy)));
   CtorBuilder.CreateCall(createRegisterGlobalsFunction(M, IsHIP), Handle);
   if (!IsHIP)
 CtorBuilder.CreateCall(RegFatbinEnd, Handle);
@@ -507,8 +503,8 @@ void createRegisterFatbinFunction(Module &M, GlobalVariable 
*FatbinDesc,
   // `atexit()` intead.
   IRBuilder<> DtorBuilder(BasicBlock::Create(C, "entry", DtorFunc));
   LoadInst *BinaryHandle = DtorBuilder.CreateAlignedLoad(
-  PointerType::getUnqual(C)->getPointerTo(), BinaryHandleGlobal,
-  Alig

[clang] [clang-linker-wrapper] Re-use type returned from 'PointerType::getUnqual(C)' (NFC) (PR #73374)

2023-11-24 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 updated 
https://github.com/llvm/llvm-project/pull/73374

>From cd36ba2c52f14051cbe82efc6390a036f75d2b46 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Thu, 23 Nov 2023 10:54:07 -0600
Subject: [PATCH 1/2] [clang-linker-wrapper] Re-use type returned from
 'PointerType::getUnqual(C)' (NFC)

Multiple calls to `PointerType::getUnqual(C)`, and calls to
`Type::getPointerTo(AddrSpace=0)` on them all result in the same type.

Clean them up to re-use the same `PtrTy` variable within function
`createRegisterGlobalsFunction()`.
---
 .../clang-linker-wrapper/OffloadWrapper.cpp   | 34 ---
 1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp 
b/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp
index 4bbfba777e1854f..5daa7c083b564e0 100644
--- a/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp
@@ -445,6 +445,7 @@ Function *createRegisterGlobalsFunction(Module &M, bool 
IsHIP) {
 void createRegisterFatbinFunction(Module &M, GlobalVariable *FatbinDesc,
   bool IsHIP) {
   LLVMContext &C = M.getContext();
+  auto *PtrTy = PointerType::getUnqual(C);
   auto *CtorFuncTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg*/ false);
   auto *CtorFunc =
   Function::Create(CtorFuncTy, GlobalValue::InternalLinkage,
@@ -458,44 +459,39 @@ void createRegisterFatbinFunction(Module &M, 
GlobalVariable *FatbinDesc,
   DtorFunc->setSection(".text.startup");
 
   // Get the __cudaRegisterFatBinary function declaration.
-  auto *RegFatTy = FunctionType::get(PointerType::getUnqual(C)->getPointerTo(),
- PointerType::getUnqual(C),
+  auto *RegFatTy = FunctionType::get(PtrTy, PtrTy,
  /*isVarArg*/ false);
   FunctionCallee RegFatbin = M.getOrInsertFunction(
   IsHIP ? "__hipRegisterFatBinary" : "__cudaRegisterFatBinary", RegFatTy);
   // Get the __cudaRegisterFatBinaryEnd function declaration.
-  auto *RegFatEndTy = FunctionType::get(
-  Type::getVoidTy(C), PointerType::getUnqual(C)->getPointerTo(),
-  /*isVarArg*/ false);
+  auto *RegFatEndTy = FunctionType::get(Type::getVoidTy(C), PtrTy,
+/*isVarArg*/ false);
   FunctionCallee RegFatbinEnd =
   M.getOrInsertFunction("__cudaRegisterFatBinaryEnd", RegFatEndTy);
   // Get the __cudaUnregisterFatBinary function declaration.
-  auto *UnregFatTy = FunctionType::get(
-  Type::getVoidTy(C), PointerType::getUnqual(C)->getPointerTo(),
-  /*isVarArg*/ false);
+  auto *UnregFatTy = FunctionType::get(Type::getVoidTy(C), PtrTy,
+   /*isVarArg*/ false);
   FunctionCallee UnregFatbin = M.getOrInsertFunction(
   IsHIP ? "__hipUnregisterFatBinary" : "__cudaUnregisterFatBinary",
   UnregFatTy);
 
-  auto *AtExitTy =
-  FunctionType::get(Type::getInt32Ty(C), DtorFuncTy->getPointerTo(),
-/*isVarArg*/ false);
+  auto *AtExitTy = FunctionType::get(Type::getInt32Ty(C), PtrTy,
+ /*isVarArg*/ false);
   FunctionCallee AtExit = M.getOrInsertFunction("atexit", AtExitTy);
 
   auto *BinaryHandleGlobal = new llvm::GlobalVariable(
-  M, PointerType::getUnqual(C)->getPointerTo(), false,
-  llvm::GlobalValue::InternalLinkage,
-  
llvm::ConstantPointerNull::get(PointerType::getUnqual(C)->getPointerTo()),
+  M, PtrTy, false, llvm::GlobalValue::InternalLinkage,
+  llvm::ConstantPointerNull::get(PtrTy),
   IsHIP ? ".hip.binary_handle" : ".cuda.binary_handle");
 
   // Create the constructor to register this image with the runtime.
   IRBuilder<> CtorBuilder(BasicBlock::Create(C, "entry", CtorFunc));
   CallInst *Handle = CtorBuilder.CreateCall(
-  RegFatbin, ConstantExpr::getPointerBitCastOrAddrSpaceCast(
- FatbinDesc, PointerType::getUnqual(C)));
+  RegFatbin,
+  ConstantExpr::getPointerBitCastOrAddrSpaceCast(FatbinDesc, PtrTy));
   CtorBuilder.CreateAlignedStore(
   Handle, BinaryHandleGlobal,
-  Align(M.getDataLayout().getPointerTypeSize(PointerType::getUnqual(C;
+  Align(M.getDataLayout().getPointerTypeSize(PtrTy)));
   CtorBuilder.CreateCall(createRegisterGlobalsFunction(M, IsHIP), Handle);
   if (!IsHIP)
 CtorBuilder.CreateCall(RegFatbinEnd, Handle);
@@ -507,8 +503,8 @@ void createRegisterFatbinFunction(Module &M, GlobalVariable 
*FatbinDesc,
   // `atexit()` intead.
   IRBuilder<> DtorBuilder(BasicBlock::Create(C, "entry", DtorFunc));
   LoadInst *BinaryHandle = DtorBuilder.CreateAlignedLoad(
-  PointerType::getUnqual(C)->getPointerTo(), BinaryHandleGlobal,
-  Align(M.getDataLayout().getPointerTypeSize(PointerType::getUnqual(C;
+  PtrTy, BinaryHandleGlobal,
+  Align(M.getDataLayout().getPointerTypeSize(PtrTy)));
   DtorBuilder.CreateCall(UnregFatbin, BinaryHandle);
   DtorBuilder.

[clang] [clang-linker-wrapper] Re-use type returned from 'PointerType::getUnqual(C)' (NFC) (PR #73374)

2023-11-24 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 updated 
https://github.com/llvm/llvm-project/pull/73374

>From cd36ba2c52f14051cbe82efc6390a036f75d2b46 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Thu, 23 Nov 2023 10:54:07 -0600
Subject: [PATCH 1/3] [clang-linker-wrapper] Re-use type returned from
 'PointerType::getUnqual(C)' (NFC)

Multiple calls to `PointerType::getUnqual(C)`, and calls to
`Type::getPointerTo(AddrSpace=0)` on them all result in the same type.

Clean them up to re-use the same `PtrTy` variable within function
`createRegisterGlobalsFunction()`.
---
 .../clang-linker-wrapper/OffloadWrapper.cpp   | 34 ---
 1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp 
b/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp
index 4bbfba777e1854f..5daa7c083b564e0 100644
--- a/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp
@@ -445,6 +445,7 @@ Function *createRegisterGlobalsFunction(Module &M, bool 
IsHIP) {
 void createRegisterFatbinFunction(Module &M, GlobalVariable *FatbinDesc,
   bool IsHIP) {
   LLVMContext &C = M.getContext();
+  auto *PtrTy = PointerType::getUnqual(C);
   auto *CtorFuncTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg*/ false);
   auto *CtorFunc =
   Function::Create(CtorFuncTy, GlobalValue::InternalLinkage,
@@ -458,44 +459,39 @@ void createRegisterFatbinFunction(Module &M, 
GlobalVariable *FatbinDesc,
   DtorFunc->setSection(".text.startup");
 
   // Get the __cudaRegisterFatBinary function declaration.
-  auto *RegFatTy = FunctionType::get(PointerType::getUnqual(C)->getPointerTo(),
- PointerType::getUnqual(C),
+  auto *RegFatTy = FunctionType::get(PtrTy, PtrTy,
  /*isVarArg*/ false);
   FunctionCallee RegFatbin = M.getOrInsertFunction(
   IsHIP ? "__hipRegisterFatBinary" : "__cudaRegisterFatBinary", RegFatTy);
   // Get the __cudaRegisterFatBinaryEnd function declaration.
-  auto *RegFatEndTy = FunctionType::get(
-  Type::getVoidTy(C), PointerType::getUnqual(C)->getPointerTo(),
-  /*isVarArg*/ false);
+  auto *RegFatEndTy = FunctionType::get(Type::getVoidTy(C), PtrTy,
+/*isVarArg*/ false);
   FunctionCallee RegFatbinEnd =
   M.getOrInsertFunction("__cudaRegisterFatBinaryEnd", RegFatEndTy);
   // Get the __cudaUnregisterFatBinary function declaration.
-  auto *UnregFatTy = FunctionType::get(
-  Type::getVoidTy(C), PointerType::getUnqual(C)->getPointerTo(),
-  /*isVarArg*/ false);
+  auto *UnregFatTy = FunctionType::get(Type::getVoidTy(C), PtrTy,
+   /*isVarArg*/ false);
   FunctionCallee UnregFatbin = M.getOrInsertFunction(
   IsHIP ? "__hipUnregisterFatBinary" : "__cudaUnregisterFatBinary",
   UnregFatTy);
 
-  auto *AtExitTy =
-  FunctionType::get(Type::getInt32Ty(C), DtorFuncTy->getPointerTo(),
-/*isVarArg*/ false);
+  auto *AtExitTy = FunctionType::get(Type::getInt32Ty(C), PtrTy,
+ /*isVarArg*/ false);
   FunctionCallee AtExit = M.getOrInsertFunction("atexit", AtExitTy);
 
   auto *BinaryHandleGlobal = new llvm::GlobalVariable(
-  M, PointerType::getUnqual(C)->getPointerTo(), false,
-  llvm::GlobalValue::InternalLinkage,
-  
llvm::ConstantPointerNull::get(PointerType::getUnqual(C)->getPointerTo()),
+  M, PtrTy, false, llvm::GlobalValue::InternalLinkage,
+  llvm::ConstantPointerNull::get(PtrTy),
   IsHIP ? ".hip.binary_handle" : ".cuda.binary_handle");
 
   // Create the constructor to register this image with the runtime.
   IRBuilder<> CtorBuilder(BasicBlock::Create(C, "entry", CtorFunc));
   CallInst *Handle = CtorBuilder.CreateCall(
-  RegFatbin, ConstantExpr::getPointerBitCastOrAddrSpaceCast(
- FatbinDesc, PointerType::getUnqual(C)));
+  RegFatbin,
+  ConstantExpr::getPointerBitCastOrAddrSpaceCast(FatbinDesc, PtrTy));
   CtorBuilder.CreateAlignedStore(
   Handle, BinaryHandleGlobal,
-  Align(M.getDataLayout().getPointerTypeSize(PointerType::getUnqual(C;
+  Align(M.getDataLayout().getPointerTypeSize(PtrTy)));
   CtorBuilder.CreateCall(createRegisterGlobalsFunction(M, IsHIP), Handle);
   if (!IsHIP)
 CtorBuilder.CreateCall(RegFatbinEnd, Handle);
@@ -507,8 +503,8 @@ void createRegisterFatbinFunction(Module &M, GlobalVariable 
*FatbinDesc,
   // `atexit()` intead.
   IRBuilder<> DtorBuilder(BasicBlock::Create(C, "entry", DtorFunc));
   LoadInst *BinaryHandle = DtorBuilder.CreateAlignedLoad(
-  PointerType::getUnqual(C)->getPointerTo(), BinaryHandleGlobal,
-  Align(M.getDataLayout().getPointerTypeSize(PointerType::getUnqual(C;
+  PtrTy, BinaryHandleGlobal,
+  Align(M.getDataLayout().getPointerTypeSize(PtrTy)));
   DtorBuilder.CreateCall(UnregFatbin, BinaryHandle);
   DtorBuilder.

[clang] [clang-linker-wrapper] Re-use type returned from 'PointerType::getUnqual(C)' (NFC) (PR #73374)

2023-11-24 Thread Youngsuk Kim via cfe-commits

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


[clang] bc6b632 - [CGOpenMPRuntimeGPU] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-11-25 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-25T11:28:18-06:00
New Revision: bc6b632723f8a025c7daa78c82f7d2ad1962a4e9

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

LOG: [CGOpenMPRuntimeGPU] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque ptr cleanup effort

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 9b8fbbdf8046787..7ddc67e8a04ab64 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1837,12 +1837,7 @@ static llvm::Value 
*emitInterWarpCopyFunction(CodeGenModule &CGM,
   {llvm::Constant::getNullValue(CGM.Int64Ty), WarpID});
   // Casting to actual data type.
   // MediumPtr = (CopyType*)MediumPtrAddr;
-  Address MediumPtr(
-  Bld.CreateBitCast(
-  MediumPtrVal,
-  CopyType->getPointerTo(
-  MediumPtrVal->getType()->getPointerAddressSpace())),
-  CopyType, Align);
+  Address MediumPtr(MediumPtrVal, CopyType, Align);
 
   // elem = *elemptr
   //*MediumPtr = elem
@@ -1889,12 +1884,7 @@ static llvm::Value 
*emitInterWarpCopyFunction(CodeGenModule &CGM,
   TransferMedium->getValueType(), TransferMedium,
   {llvm::Constant::getNullValue(CGM.Int64Ty), ThreadID});
   // SrcMediumVal = *SrcMediumPtr;
-  Address SrcMediumPtr(
-  Bld.CreateBitCast(
-  SrcMediumPtrVal,
-  CopyType->getPointerTo(
-  SrcMediumPtrVal->getType()->getPointerAddressSpace())),
-  CopyType, Align);
+  Address SrcMediumPtr(SrcMediumPtrVal, CopyType, Align);
 
   // TargetElemPtr = (CopyType*)(SrcDataAddr[i]) + I
   Address TargetElemPtrPtr = Bld.CreateConstArrayGEP(LocalReduceList, Idx);



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


[clang] 328fd36 - [clang][CGStmtOpenMP] Remove unneeded calls to CreatePointerBitCastOrAddrSpaceCast (NFC)

2023-11-29 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-29T14:59:27-06:00
New Revision: 328fd363daabb464670613dece6c75cf99d03410

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

LOG: [clang][CGStmtOpenMP] Remove unneeded calls to 
CreatePointerBitCastOrAddrSpaceCast (NFC)

Opaque ptr cleanup effort (NFC).

Added: 


Modified: 
clang/lib/CodeGen/CGStmtOpenMP.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 478d6dbf9ca81d9..90c7ed450e54b99 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -667,11 +667,7 @@ CodeGenFunction::GenerateOpenMPCapturedStmtFunction(const 
CapturedStmt &S,
   I->second.first ? I->second.first->getType() : Arg->getType(),
   AlignmentSource::Decl);
   if (LV.getType()->isAnyComplexType())
-LV.setAddress(WrapperCGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
-LV.getAddress(WrapperCGF),
-PI->getType()->getPointerTo(
-LV.getAddress(WrapperCGF).getAddressSpace()),
-PI->getType()));
+
LV.setAddress(LV.getAddress(WrapperCGF).withElementType(PI->getType()));
   CallArg = WrapperCGF.EmitLoadOfScalar(LV, S.getBeginLoc());
 } else {
   auto EI = VLASizes.find(Arg);
@@ -4828,8 +4824,6 @@ void CodeGenFunction::EmitOMPTaskBasedDirective(
   }
   auto *CopyFnTy = llvm::FunctionType::get(CGF.Builder.getVoidTy(),
ParamTypes, /*isVarArg=*/false);
-  CopyFn = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
-  CopyFn, CopyFnTy->getPointerTo());
   CGF.CGM.getOpenMPRuntime().emitOutlinedFunctionCall(
   CGF, S.getBeginLoc(), {CopyFnTy, CopyFn}, CallArgs);
   for (const auto &Pair : LastprivateDstsOrigs) {
@@ -5115,8 +5109,6 @@ void CodeGenFunction::EmitOMPTargetTaskBasedDirective(
   }
   auto *CopyFnTy = llvm::FunctionType::get(CGF.Builder.getVoidTy(),
ParamTypes, /*isVarArg=*/false);
-  CopyFn = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
-  CopyFn, CopyFnTy->getPointerTo());
   CGF.CGM.getOpenMPRuntime().emitOutlinedFunctionCall(
   CGF, S.getBeginLoc(), {CopyFnTy, CopyFn}, CallArgs);
   for (const auto &Pair : PrivatePtrs) {



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


[clang] ff485a0 - [clang] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-11-30 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-30T14:00:31-06:00
New Revision: ff485a0e77a55847cb50768b01c04fe45a6879ea

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

LOG: [clang] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque ptr cleanup effort (NFC).

Added: 


Modified: 
clang/lib/CodeGen/CGObjC.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index fff89c8939a55a4..acc85165a470be7 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -827,11 +827,8 @@ static void emitStructGetterCall(CodeGenFunction &CGF, 
ObjCIvarDecl *ivar,
   //  sizeof (Type of Ivar), isAtomic, false);
   CallArgList args;
 
-  llvm::Value *dest =
-  CGF.Builder.CreateBitCast(CGF.ReturnValue.getPointer(), CGF.VoidPtrTy);
+  llvm::Value *dest = CGF.ReturnValue.getPointer();
   args.add(RValue::get(dest), Context.VoidPtrTy);
-
-  src = CGF.Builder.CreateBitCast(src, CGF.VoidPtrTy);
   args.add(RValue::get(src), Context.VoidPtrTy);
 
   CharUnits size = CGF.getContext().getTypeSizeInChars(ivar->getType());
@@ -1098,7 +1095,6 @@ static void emitCPPObjectAtomicGetterCall(CodeGenFunction 
&CGF,
   llvm::Value *ivarAddr =
   CGF.EmitLValueForIvar(CGF.TypeOfSelfObject(), CGF.LoadObjCSelf(), ivar, 
0)
   .getPointer(CGF);
-  ivarAddr = CGF.Builder.CreateBitCast(ivarAddr, CGF.Int8PtrTy);
   args.add(RValue::get(ivarAddr), CGF.getContext().VoidPtrTy);
 
   // Third argument is the helper function.
@@ -1340,7 +1336,6 @@ static void emitStructSetterCall(CodeGenFunction &CGF, 
ObjCMethodDecl *OMD,
  argVar->getType().getNonReferenceType(), VK_LValue,
  SourceLocation());
   llvm::Value *argAddr = CGF.EmitLValue(&argRef).getPointer(CGF);
-  argAddr = CGF.Builder.CreateBitCast(argAddr, CGF.Int8PtrTy);
   args.add(RValue::get(argAddr), CGF.getContext().VoidPtrTy);
 
   // The third argument is the sizeof the type.
@@ -1377,7 +1372,6 @@ static void emitCPPObjectAtomicSetterCall(CodeGenFunction 
&CGF,
   llvm::Value *ivarAddr =
   CGF.EmitLValueForIvar(CGF.TypeOfSelfObject(), CGF.LoadObjCSelf(), ivar, 
0)
   .getPointer(CGF);
-  ivarAddr = CGF.Builder.CreateBitCast(ivarAddr, CGF.Int8PtrTy);
   args.add(RValue::get(ivarAddr), CGF.getContext().VoidPtrTy);
 
   // The second argument is the address of the parameter variable.
@@ -1386,7 +1380,6 @@ static void emitCPPObjectAtomicSetterCall(CodeGenFunction 
&CGF,
  argVar->getType().getNonReferenceType(), VK_LValue,
  SourceLocation());
   llvm::Value *argAddr = CGF.EmitLValue(&argRef).getPointer(CGF);
-  argAddr = CGF.Builder.CreateBitCast(argAddr, CGF.Int8PtrTy);
   args.add(RValue::get(argAddr), CGF.getContext().VoidPtrTy);
 
   // Third argument is the helper function.
@@ -3685,7 +3678,6 @@ void CodeGenFunction::EmitExtendGCLifetime(llvm::Value 
*object) {
/* constraints */ "r",
/* side effects */ true);
 
-  object = Builder.CreateBitCast(object, VoidPtrTy);
   EmitNounwindRuntimeCall(extender, object);
 }
 

diff  --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 44b9acdee62648a..172c4c937b97280 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -2266,7 +2266,6 @@ MicrosoftCXXABI::performReturnAdjustment(CodeGenFunction 
&CGF, Address Ret,
   if (RA.isEmpty())
 return Ret.getPointer();
 
-  auto OrigTy = Ret.getType();
   Ret = Ret.withElementType(CGF.Int8Ty);
 
   llvm::Value *V = Ret.getPointer();
@@ -2283,8 +2282,7 @@ MicrosoftCXXABI::performReturnAdjustment(CodeGenFunction 
&CGF, Address Ret,
   if (RA.NonVirtual)
 V = CGF.Builder.CreateConstInBoundsGEP1_32(CGF.Int8Ty, V, RA.NonVirtual);
 
-  // Cast back to the original type.
-  return CGF.Builder.CreateBitCast(V, OrigTy);
+  return V;
 }
 
 bool MicrosoftCXXABI::requiresArrayCookie(const CXXDeleteExpr *expr,



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


[clang] [clang][RISCVVEmitter] Remove no-op ptr-to-ptr bitcast (NFC) (PR #74179)

2023-12-01 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 created 
https://github.com/llvm/llvm-project/pull/74179

Remove ptr-to-ptr bitcast which was added back in 
939352b6ec31db4e8defe07856868438fbc5340d . With opaque pointers, the bitcast is 
now redundant.

Opaque ptr cleanup effort.

>From 56eb182b28277cc6160e6916d98a02b1ee12fadb Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Fri, 1 Dec 2023 21:59:59 -0600
Subject: [PATCH] [clang][RISCVVEmitter] Remove no-op ptr-to-ptr bitcast (NFC)

Remove ptr-to-ptr bitcast which was added back in 
939352b6ec31db4e8defe07856868438fbc5340d .
With opaque pointers, the bitcast is now redundant.

Opaque ptr cleanup effort.
---
 clang/utils/TableGen/RISCVVEmitter.cpp | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/clang/utils/TableGen/RISCVVEmitter.cpp 
b/clang/utils/TableGen/RISCVVEmitter.cpp
index cf731e8414a3b83..1fb41805a0473dd 100644
--- a/clang/utils/TableGen/RISCVVEmitter.cpp
+++ b/clang/utils/TableGen/RISCVVEmitter.cpp
@@ -180,13 +180,10 @@ void emitCodeGenSwitchBody(const RVVIntrinsic *RVVI, 
raw_ostream &OS) {
 return;
   }
 
-  // Cast pointer operand of vector load intrinsic.
   for (const auto &I : enumerate(RVVI->getInputTypes())) {
 if (I.value()->isPointer()) {
   assert(RVVI->getIntrinsicTypes().front() == -1 &&
  "RVVI should be vector load intrinsic.");
-  OS << "  Ops[" << I.index() << "] = Builder.CreateBitCast(Ops[";
-  OS << I.index() << "], ResultType->getPointerTo());\n";
 }
   }
 

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


[clang] [clang][RISCVVEmitter] Remove no-op ptr-to-ptr bitcast (NFC) (PR #74179)

2023-12-02 Thread Youngsuk Kim via cfe-commits

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


[clang] [clang][CGOpenMPRuntimeGPU] Merge consecutive AddrSpaceCasts (NFC) (PR #74279)

2023-12-03 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 created 
https://github.com/llvm/llvm-project/pull/74279

Merge consecutive AddrSpaceCasts into a single AddrSpaceCast.

>From 4e86272d980b26bf1240df94cbc894e7ded0d018 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Sun, 3 Dec 2023 23:52:33 -0600
Subject: [PATCH] [clang][CGOpenMPRuntimeGPU] Merge consecutive AddrSpaceCasts
 (NFC)

Merge consecutive AddrSpaceCasts into a single AddrSpaceCast.
---
 clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 5b9dbbf7e83a9..293ccaa3413cd 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -3017,11 +3017,7 @@ CGOpenMPRuntimeGPU::getParameterAddress(CodeGenFunction 
&CGF,
   QualType TargetTy = TargetParam->getType();
   llvm::Value *TargetAddr = CGF.EmitLoadOfScalar(LocalAddr, /*Volatile=*/false,
  TargetTy, SourceLocation());
-  // First cast to generic.
-  TargetAddr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
-  TargetAddr,
-  llvm::PointerType::get(CGF.getLLVMContext(), /*AddrSpace=*/0));
-  // Cast from generic to native address space.
+  // Cast to native address space.
   TargetAddr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
   TargetAddr,
   llvm::PointerType::get(CGF.getLLVMContext(), NativePointeeAddrSpace));
@@ -3048,11 +3044,8 @@ void CGOpenMPRuntimeGPU::emitOutlinedFunctionCall(
   TargetArgs.emplace_back(NativeArg);
   continue;
 }
-llvm::Value *TargetArg = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
-NativeArg,
-llvm::PointerType::get(CGF.getLLVMContext(), /*AddrSpace*/ 0));
 TargetArgs.emplace_back(
-CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(TargetArg, 
TargetType));
+CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(NativeArg, 
TargetType));
   }
   CGOpenMPRuntime::emitOutlinedFunctionCall(CGF, Loc, OutlinedFn, TargetArgs);
 }

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


[clang] [clang-format] Fix a bug in `git-clang-format --binary` (PR #74176)

2023-12-03 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

I've been using `git clang-format` without the `--bin` flag using the following 
setting

1. `PATH=$PATH:~/llvm-project/build/bin:~/llvm-project/clang/tools/clang-format`
2. Run `git clang-format HEAD~1` at `~/llvm-project` directory

After this revision, I get the following error:
```
error: cannot find executable 
"/llvm-project/clang-format"
```
( = full path to the parent directory of 
`llvm-project` directory)

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


[clang] [clang][CGOpenMPRuntimeGPU] Merge consecutive AddrSpaceCasts (NFC) (PR #74279)

2023-12-04 Thread Youngsuk Kim via cfe-commits

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


[clang] [Clang][Sema] Warn unused cxx var declared in condition of if-statement (PR #87348)

2024-04-02 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 created 
https://github.com/llvm/llvm-project/pull/87348

Fixes #41447 

>From 90834d7250d18c9389c84966279365638dce80a9 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Tue, 2 Apr 2024 08:17:36 -0500
Subject: [PATCH] [Clang][Sema] Warn unused cxx var declared in condition of
 if-statement

---
 clang/include/clang/AST/Decl.h   | 12 
 clang/lib/Sema/SemaDecl.cpp  |  8 ++--
 clang/lib/Sema/SemaDeclCXX.cpp   |  3 +++
 .../SemaCXX/warn-unused-but-set-variables-cpp.cpp|  6 ++
 4 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index a5879591f4c659..5f1f83bb00282f 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -1100,6 +1100,9 @@ class VarDecl : public DeclaratorDecl, public 
Redeclarable {
 
 LLVM_PREFERRED_TYPE(bool)
 unsigned EscapingByref : 1;
+
+LLVM_PREFERRED_TYPE(bool)
+unsigned IsCXXCondDecl : 1;
   };
 
   union {
@@ -1589,6 +1592,15 @@ class VarDecl : public DeclaratorDecl, public 
Redeclarable {
 NonParmVarDeclBits.EscapingByref = true;
   }
 
+  bool isCXXCondDecl() const {
+return isa(this) ? false : NonParmVarDeclBits.IsCXXCondDecl;
+  }
+
+  void setCXXCondDecl() {
+assert(!isa(this));
+NonParmVarDeclBits.IsCXXCondDecl = true;
+  }
+
   /// Determines if this variable's alignment is dependent.
   bool hasDependentAlignment() const;
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 8b44d24f5273aa..62f71658fa3b5a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2188,8 +2188,12 @@ void Sema::DiagnoseUnusedButSetDecl(const VarDecl *VD,
 
   assert(iter->getSecond() >= 0 &&
  "Found a negative number of references to a VarDecl");
-  if (iter->getSecond() != 0)
-return;
+  if (iter->getSecond() != 0) {
+bool UnusedCXXCondDecl = VD->isCXXCondDecl() && (iter->getSecond() == 1);
+if (!UnusedCXXCondDecl)
+  return;
+  }
+
   unsigned DiagID = isa(VD) ? diag::warn_unused_but_set_parameter
  : diag::warn_unused_but_set_variable;
   DiagReceiver(VD->getLocation(), PDiag(DiagID) << VD);
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index e9fecaea84b021..d4d69beeba5a05 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -18563,6 +18563,9 @@ DeclResult Sema::ActOnCXXConditionDeclaration(Scope *S, 
Declarator &D) {
 return true;
   }
 
+  if (auto *VD = dyn_cast(Dcl))
+VD->setCXXCondDecl();
+
   return Dcl;
 }
 
diff --git a/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp 
b/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
index 418baa78aa964b..cb066e209cb453 100644
--- a/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
+++ b/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
@@ -69,3 +69,9 @@ template  void f5() {
   SWarnUnused swu;
   ++swu;
 }
+
+void f6() {
+  if (int x = 123) { // expected-warning{{variable 'x' set but not used}}
+;
+  }
+}

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


[clang] [clang][Sema] Warn on return of pointer/reference to compound literal (PR #83741)

2024-03-03 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 created 
https://github.com/llvm/llvm-project/pull/83741

Emit a warning if pointer/reference to compound literal is returned from a 
function.

In C, compound literals in block scope are lvalues that have automatic storage 
duration. In C++, compound literals in block scope are temporaries.

In either case, returning a pointer/reference to a compound literal can cause a 
use-after-free bug.

Fixes #8678 

>From fc0cb9c44ec7945f1a88420675b667167908e07c Mon Sep 17 00:00:00 2001
From: JOE1994 
Date: Sun, 3 Mar 2024 12:38:49 -0500
Subject: [PATCH] [clang][Sema] Warn on return of pointer/reference to compound
 literal

Emit a warning if pointer/reference to compound literal is returned from a 
function.

In C, compound literals in block scope are lvalues that have automatic storage 
duration.
In C++, compound literals in block scope are temporaries.

In either case, returning a pointer/reference to a compound literal
can cause a use-after-free bug.
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  2 +-
 clang/lib/Sema/SemaInit.cpp  | 12 
 clang/test/Analysis/stack-addr-ps.c  |  4 ++--
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 91105d4231f06a..f5c88b8ae5aade 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9898,7 +9898,7 @@ def err_lifetimebound_ctor_dtor : Error<
 // CHECK: returning address/reference of stack memory
 def warn_ret_stack_addr_ref : Warning<
   "%select{address of|reference to}0 stack memory associated with "
-  "%select{local variable|parameter}2 %1 returned">,
+  "%select{local variable|parameter|compound literal}2 %1 returned">,
   InGroup;
 def warn_ret_local_temp_addr_ref : Warning<
   "returning %select{address of|reference to}0 local temporary object">,
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 0fd458837163e5..93b125382b164f 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7734,6 +7734,14 @@ static void 
visitLocalsRetainedByReferenceBinding(IndirectLocalPath &Path,
 break;
   }
 
+  case Stmt::CompoundLiteralExprClass: {
+if (auto *CLE = dyn_cast(Init)) {
+  if (!CLE->isFileScope())
+Visit(Path, Local(CLE), RK);
+}
+break;
+  }
+
   // FIXME: Visit the left-hand side of an -> or ->*.
 
   default:
@@ -8289,6 +8297,10 @@ void Sema::checkInitializerLifetime(const 
InitializedEntity &Entity,
 if (LK == LK_StmtExprResult)
   return false;
 Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
+  } else if (auto *CLE = dyn_cast(L)) {
+Diag(DiagLoc, diag::warn_ret_stack_addr_ref)
+<< Entity.getType()->isReferenceType() << CLE->getInitializer() << 
2
+<< DiagRange;
   } else {
 Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)
  << Entity.getType()->isReferenceType() << DiagRange;
diff --git a/clang/test/Analysis/stack-addr-ps.c 
b/clang/test/Analysis/stack-addr-ps.c
index 26e1cc58350cab..e469396e1bb22a 100644
--- a/clang/test/Analysis/stack-addr-ps.c
+++ b/clang/test/Analysis/stack-addr-ps.c
@@ -20,13 +20,13 @@ int* f3(int x, int *y) {
 
 void* compound_literal(int x, int y) {
   if (x)
-return &(unsigned short){((unsigned short)0x22EF)}; // 
expected-warning{{Address of stack memory}}
+return &(unsigned short){((unsigned short)0x22EF)}; // 
expected-warning{{Address of stack memory}} expected-warning{{address of stack 
memory}}
 
   int* array[] = {};
   struct s { int z; double y; int w; };
   
   if (y)
-return &((struct s){ 2, 0.4, 5 * 8 }); // expected-warning{{Address of 
stack memory}}
+return &((struct s){ 2, 0.4, 5 * 8 }); // expected-warning{{Address of 
stack memory}} expected-warning{{address of stack memory}}
 
   
   void* p = &((struct s){ 42, 0.4, x ? 42 : 0 });

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


[clang] [clang][Sema] Warn on return of pointer/reference to compound literal (PR #83741)

2024-03-03 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

> Isn't this warning a duplicate of what is already here?

The diganostic warning is not emitted when `clang` is run without the 
`-analyze` flag.

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


[clang] [ObjC] Check entire chain of superclasses to see if class layout is statically known (PR #81335)

2024-03-03 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

> @JOE1994 Thoughts on this?

I'm not an ideal reviewer for this as I'm unfamiliar with ObjC side of Clang,
but I'll come back to leave a review and to help merge this if this doesn't get 
merged by the end of the day :)

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


[clang] [clang][Sema] Warn on return of pointer/reference to compound literal (PR #83741)

2024-03-04 Thread Youngsuk Kim via cfe-commits

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


[clang] [ObjC] Check entire chain of superclasses to see if class layout is statically known (PR #81335)

2024-03-05 Thread Youngsuk Kim via cfe-commits

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

LGTM

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


[clang] [ObjC] Check entire chain of superclasses to see if class layout is statically known (PR #81335)

2024-03-05 Thread Youngsuk Kim via cfe-commits

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


[clang] 8e00d59 - [clang] Remove redundant ptr-to-ptr bitcasts (NFC)

2023-10-25 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-10-25T10:36:52-05:00
New Revision: 8e00d59dce23f841586260092bddde8a4a26d75f

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

LOG: [clang] Remove redundant ptr-to-ptr bitcasts (NFC)

Remove redundant bitcasts performed on instances of
`llvm::GlobalVariable`, which are pointers.

Opaque pointer cleanup effort. NFC.

Added: 


Modified: 
clang/lib/CodeGen/CGCUDANV.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 2ef4dc236d091b0..66147f656071f53 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -556,7 +556,7 @@ llvm::Function *CGNVCUDARuntime::makeRegisterGlobalsFn() {
 llvm::Constant *NullPtr = llvm::ConstantPointerNull::get(VoidPtrTy);
 llvm::Value *Args[] = {
 &GpuBinaryHandlePtr,
-Builder.CreateBitCast(KernelHandles[I.Kernel->getName()], VoidPtrTy),
+KernelHandles[I.Kernel->getName()],
 KernelName,
 KernelName,
 llvm::ConstantInt::get(IntTy, -1),
@@ -631,8 +631,8 @@ llvm::Function *CGNVCUDARuntime::makeRegisterGlobalsFn() {
 replaceManagedVar(Var, ManagedVar);
 llvm::Value *Args[] = {
 &GpuBinaryHandlePtr,
-Builder.CreateBitCast(ManagedVar, VoidPtrTy),
-Builder.CreateBitCast(Var, VoidPtrTy),
+ManagedVar,
+Var,
 VarName,
 llvm::ConstantInt::get(VarSizeTy, VarSize),
 llvm::ConstantInt::get(IntTy, Var->getAlignment())};
@@ -641,7 +641,7 @@ llvm::Function *CGNVCUDARuntime::makeRegisterGlobalsFn() {
   } else {
 llvm::Value *Args[] = {
 &GpuBinaryHandlePtr,
-Builder.CreateBitCast(Var, VoidPtrTy),
+Var,
 VarName,
 VarName,
 llvm::ConstantInt::get(IntTy, Info.Flags.isExtern()),
@@ -655,15 +655,15 @@ llvm::Function *CGNVCUDARuntime::makeRegisterGlobalsFn() {
 case DeviceVarFlags::Surface:
   Builder.CreateCall(
   RegisterSurf,
-  {&GpuBinaryHandlePtr, Builder.CreateBitCast(Var, VoidPtrTy), VarName,
-   VarName, llvm::ConstantInt::get(IntTy, Info.Flags.getSurfTexType()),
+  {&GpuBinaryHandlePtr, Var, VarName, VarName,
+   llvm::ConstantInt::get(IntTy, Info.Flags.getSurfTexType()),
llvm::ConstantInt::get(IntTy, Info.Flags.isExtern())});
   break;
 case DeviceVarFlags::Texture:
   Builder.CreateCall(
   RegisterTex,
-  {&GpuBinaryHandlePtr, Builder.CreateBitCast(Var, VoidPtrTy), VarName,
-   VarName, llvm::ConstantInt::get(IntTy, Info.Flags.getSurfTexType()),
+  {&GpuBinaryHandlePtr, Var, VarName, VarName,
+   llvm::ConstantInt::get(IntTy, Info.Flags.getSurfTexType()),
llvm::ConstantInt::get(IntTy, Info.Flags.isNormalized()),
llvm::ConstantInt::get(IntTy, Info.Flags.isExtern())});
   break;
@@ -860,9 +860,8 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
 {
   CtorBuilder.SetInsertPoint(IfBlock);
   // GpuBinaryHandle = __hipRegisterFatBinary(&FatbinWrapper);
-  llvm::CallInst *RegisterFatbinCall = CtorBuilder.CreateCall(
-  RegisterFatbinFunc,
-  CtorBuilder.CreateBitCast(FatbinWrapper, VoidPtrTy));
+  llvm::CallInst *RegisterFatbinCall =
+  CtorBuilder.CreateCall(RegisterFatbinFunc, FatbinWrapper);
   CtorBuilder.CreateStore(RegisterFatbinCall, GpuBinaryAddr);
   CtorBuilder.CreateBr(ExitBlock);
 }
@@ -878,9 +877,8 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
 // Register binary with CUDA runtime. This is substantially 
diff erent in
 // default mode vs. separate compilation!
 // GpuBinaryHandle = __cudaRegisterFatBinary(&FatbinWrapper);
-llvm::CallInst *RegisterFatbinCall = CtorBuilder.CreateCall(
-RegisterFatbinFunc,
-CtorBuilder.CreateBitCast(FatbinWrapper, VoidPtrTy));
+llvm::CallInst *RegisterFatbinCall =
+CtorBuilder.CreateCall(RegisterFatbinFunc, FatbinWrapper);
 GpuBinaryHandle = new llvm::GlobalVariable(
 TheModule, VoidPtrPtrTy, false, llvm::GlobalValue::InternalLinkage,
 llvm::ConstantPointerNull::get(VoidPtrPtrTy), "__cuda_gpubin_handle");
@@ -921,9 +919,7 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
 getRegisterLinkedBinaryFnTy(), RegisterLinkedBinaryName);
 
 assert(RegisterGlobalsFunc && "Expecting at least dummy function!");
-llvm::Value *Args[] = {RegisterGlobalsFunc,
-   CtorBuilder.CreateBitCast(FatbinWrapper, VoidPtrTy),
-   ModuleIDConstant,
+llvm::Value *Args[] = {RegisterGlobalsFunc, FatbinWrapper, 
ModuleIDConstant,

[clang] [clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast (NFC) (PR #68277)

2023-10-04 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 created 
https://github.com/llvm/llvm-project/pull/68277

With opaque pointers, CreatePointerBitCastOrAddrSpaceCast is same as 
CreateAddrSpaceCast. Replace or remove uses of 
CreatePointerBitCastOrAddrSpaceCast.

Opaque pointer cleanup effort.

>From 1299c48eb032aa7543f5c4569de75b45ef07bfb5 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Mon, 2 Oct 2023 12:28:33 -0400
Subject: [PATCH] [clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast
 (NFC)

With opaque pointers, CreatePointerBitCastOrAddrSpaceCast is same as 
CreateAddrSpaceCast.
Replace or remove uses of CreatePointerBitCastOrAddrSpaceCast.

Opaque pointer cleanup effort.
---
 clang/lib/CodeGen/CGCall.cpp  | 2 +-
 clang/lib/CodeGen/CodeGenFunction.cpp | 3 +--
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 3 ---
 clang/lib/CodeGen/TargetInfo.cpp  | 2 +-
 llvm/include/llvm/IR/IRBuilder.h  | 2 ++
 5 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 93e16575042c4da..b0d1fcd26a5f413 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1376,7 +1376,7 @@ static void CreateCoercedStore(llvm::Value *Src,
   llvm::PointerType *DstPtrTy = llvm::dyn_cast(DstTy);
   if (SrcPtrTy && DstPtrTy &&
   SrcPtrTy->getAddressSpace() != DstPtrTy->getAddressSpace()) {
-Src = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(Src, DstTy);
+Src = CGF.Builder.CreateAddrSpaceCast(Src, DstTy);
 CGF.Builder.CreateStore(Src, Dst, DstIsVolatile);
 return;
   }
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 9b21f428b0af7f5..05f8c459a346583 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1123,8 +1123,7 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
 if (!CurFnInfo->getReturnInfo().getIndirectByVal()) {
   ReturnValuePointer =
   CreateDefaultAlignTempAlloca(Int8PtrTy, "result.ptr");
-  Builder.CreateStore(Builder.CreatePointerBitCastOrAddrSpaceCast(
-  ReturnValue.getPointer(), Int8PtrTy),
+  Builder.CreateStore(ReturnValue.getPointer(),
   ReturnValuePointer);
 }
   } else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::InAlloca &&
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 0c89871420bdd3d..f7ef9503aa61033 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -3088,9 +3088,6 @@ void ItaniumCXXABI::EmitThreadLocalInitFuncs(
   CharUnits Align = CGM.getContext().getDeclAlign(VD);
   Val = Builder.CreateAlignedLoad(Var->getValueType(), Val, Align);
 }
-if (Val->getType() != Wrapper->getReturnType())
-  Val = Builder.CreatePointerBitCastOrAddrSpaceCast(
-  Val, Wrapper->getReturnType(), "");
 
 Builder.CreateRet(Val);
   }
diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp
index 3d79f92137abc79..60224d458f6a262 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -137,7 +137,7 @@ llvm::Value *TargetCodeGenInfo::performAddrSpaceCast(
   if (auto *C = dyn_cast(Src))
 return performAddrSpaceCast(CGF.CGM, C, SrcAddr, DestAddr, DestTy);
   // Try to preserve the source's name to make IR more readable.
-  return CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
+  return CGF.Builder.CreateAddrSpaceCast(
   Src, DestTy, Src->hasName() ? Src->getName() + ".ascast" : "");
 }
 
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index c9f243fdb12e404..a32ec9a66fedfa8 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -2138,6 +2138,8 @@ class IRBuilderBase {
 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
   }
 
+  // With opaque pointers enabled, this is same as CreateAddressSpaceCast.
+  // TODO: Replace uses of this method and remove the method itself.
   Value *CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy,
  const Twine &Name = "") {
 if (V->getType() == DestTy)

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


[clang] [clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast (NFC) (PR #68277)

2023-10-04 Thread Youngsuk Kim via cfe-commits


@@ -3088,9 +3088,6 @@ void ItaniumCXXABI::EmitThreadLocalInitFuncs(
   CharUnits Align = CGM.getContext().getDeclAlign(VD);
   Val = Builder.CreateAlignedLoad(Var->getValueType(), Val, Align);
 }
-if (Val->getType() != Wrapper->getReturnType())
-  Val = Builder.CreatePointerBitCastOrAddrSpaceCast(

JOE1994 wrote:

Stripping the call to `CreatePointerBitCastOrAddrSpaceCast` doesn't cause any 
new `ninja check-clang` failures.

But.. I'm not entirely sure whether stripping the call is justified.

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


[clang] [clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast (NFC) (PR #68277)

2023-10-04 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 updated 
https://github.com/llvm/llvm-project/pull/68277

>From 2c3fb032e7fdefa553ed4833bbeed8852eb6a410 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Mon, 2 Oct 2023 12:28:33 -0400
Subject: [PATCH] [clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast
 (NFC)

With opaque pointers, CreatePointerBitCastOrAddrSpaceCast is same as 
CreateAddrSpaceCast.
Replace or remove uses of CreatePointerBitCastOrAddrSpaceCast.

Opaque pointer cleanup effort.
---
 clang/lib/CodeGen/CGCall.cpp  | 2 +-
 clang/lib/CodeGen/CodeGenFunction.cpp | 4 +---
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 3 ---
 clang/lib/CodeGen/TargetInfo.cpp  | 2 +-
 llvm/include/llvm/IR/IRBuilder.h  | 2 ++
 5 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 93e16575042c4da..b0d1fcd26a5f413 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1376,7 +1376,7 @@ static void CreateCoercedStore(llvm::Value *Src,
   llvm::PointerType *DstPtrTy = llvm::dyn_cast(DstTy);
   if (SrcPtrTy && DstPtrTy &&
   SrcPtrTy->getAddressSpace() != DstPtrTy->getAddressSpace()) {
-Src = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(Src, DstTy);
+Src = CGF.Builder.CreateAddrSpaceCast(Src, DstTy);
 CGF.Builder.CreateStore(Src, Dst, DstIsVolatile);
 return;
   }
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 9b21f428b0af7f5..2f1954fad80f159 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1123,9 +1123,7 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
 if (!CurFnInfo->getReturnInfo().getIndirectByVal()) {
   ReturnValuePointer =
   CreateDefaultAlignTempAlloca(Int8PtrTy, "result.ptr");
-  Builder.CreateStore(Builder.CreatePointerBitCastOrAddrSpaceCast(
-  ReturnValue.getPointer(), Int8PtrTy),
-  ReturnValuePointer);
+  Builder.CreateStore(ReturnValue.getPointer(), ReturnValuePointer);
 }
   } else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::InAlloca &&
  !hasScalarEvaluationKind(CurFnInfo->getReturnType())) {
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 0c89871420bdd3d..f7ef9503aa61033 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -3088,9 +3088,6 @@ void ItaniumCXXABI::EmitThreadLocalInitFuncs(
   CharUnits Align = CGM.getContext().getDeclAlign(VD);
   Val = Builder.CreateAlignedLoad(Var->getValueType(), Val, Align);
 }
-if (Val->getType() != Wrapper->getReturnType())
-  Val = Builder.CreatePointerBitCastOrAddrSpaceCast(
-  Val, Wrapper->getReturnType(), "");
 
 Builder.CreateRet(Val);
   }
diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp
index 3d79f92137abc79..60224d458f6a262 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -137,7 +137,7 @@ llvm::Value *TargetCodeGenInfo::performAddrSpaceCast(
   if (auto *C = dyn_cast(Src))
 return performAddrSpaceCast(CGF.CGM, C, SrcAddr, DestAddr, DestTy);
   // Try to preserve the source's name to make IR more readable.
-  return CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
+  return CGF.Builder.CreateAddrSpaceCast(
   Src, DestTy, Src->hasName() ? Src->getName() + ".ascast" : "");
 }
 
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index c9f243fdb12e404..a32ec9a66fedfa8 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -2138,6 +2138,8 @@ class IRBuilderBase {
 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
   }
 
+  // With opaque pointers enabled, this is same as CreateAddressSpaceCast.
+  // TODO: Replace uses of this method and remove the method itself.
   Value *CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy,
  const Twine &Name = "") {
 if (V->getType() == DestTy)

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


[clang] [clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast (NFC) (PR #68277)

2023-10-04 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

Applied git clang-format.

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


[clang] [clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast (NFC) (PR #68277)

2023-10-04 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

No new regressions with `ninja check-clang`

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


[clang] [clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast (NFC) (PR #68277)

2023-10-05 Thread Youngsuk Kim via cfe-commits


@@ -2138,6 +2138,8 @@ class IRBuilderBase {
 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
   }
 
+  // With opaque pointers enabled, this is same as CreateAddressSpaceCast.

JOE1994 wrote:

> If the types (= address spaces) are the same, 
> CreatePointerBitCastOrAddrSpaceCast does nothing, while 
> CreateAddressSpaceCast aborts. That is, they are equivalent iff the types are 
> different.

Thank you for the clarification!

So `CreateAddrSpaceCast` and `CreatePointerBitCastOrAddrSpaceCast` aren't 
strict equivalents,
but it still seems that uses of `CreatePointerBitCastOrAddrSpaceCast` can be 
substituted with `CreateAddrSpaceCast`.

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


[clang] [clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast (NFC) (PR #68277)

2023-10-05 Thread Youngsuk Kim via cfe-commits


@@ -2138,6 +2138,8 @@ class IRBuilderBase {
 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
   }
 
+  // With opaque pointers enabled, this is same as CreateAddressSpaceCast.

JOE1994 wrote:

```suggestion
  // With opaque pointers enabled, this can be substituted with 
CreateAddrSpaceCast.
```

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


[clang] [clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast (NFC) (PR #68277)

2023-10-05 Thread Youngsuk Kim via cfe-commits


@@ -3088,9 +3088,6 @@ void ItaniumCXXABI::EmitThreadLocalInitFuncs(
   CharUnits Align = CGM.getContext().getDeclAlign(VD);
   Val = Builder.CreateAlignedLoad(Var->getValueType(), Val, Align);
 }
-if (Val->getType() != Wrapper->getReturnType())
-  Val = Builder.CreatePointerBitCastOrAddrSpaceCast(

JOE1994 wrote:

Maybe I should play safe by just replacing the call to `CreateAddrSpaceCast` 
instead of stripping it entirely.



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


[clang] [clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast (NFC) (PR #68277)

2023-10-05 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 updated 
https://github.com/llvm/llvm-project/pull/68277

>From 2c3fb032e7fdefa553ed4833bbeed8852eb6a410 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Mon, 2 Oct 2023 12:28:33 -0400
Subject: [PATCH 1/2] [clang] Replace uses of
 CreatePointerBitCastOrAddrSpaceCast (NFC)

With opaque pointers, CreatePointerBitCastOrAddrSpaceCast is same as 
CreateAddrSpaceCast.
Replace or remove uses of CreatePointerBitCastOrAddrSpaceCast.

Opaque pointer cleanup effort.
---
 clang/lib/CodeGen/CGCall.cpp  | 2 +-
 clang/lib/CodeGen/CodeGenFunction.cpp | 4 +---
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 3 ---
 clang/lib/CodeGen/TargetInfo.cpp  | 2 +-
 llvm/include/llvm/IR/IRBuilder.h  | 2 ++
 5 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 93e16575042c4da..b0d1fcd26a5f413 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1376,7 +1376,7 @@ static void CreateCoercedStore(llvm::Value *Src,
   llvm::PointerType *DstPtrTy = llvm::dyn_cast(DstTy);
   if (SrcPtrTy && DstPtrTy &&
   SrcPtrTy->getAddressSpace() != DstPtrTy->getAddressSpace()) {
-Src = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(Src, DstTy);
+Src = CGF.Builder.CreateAddrSpaceCast(Src, DstTy);
 CGF.Builder.CreateStore(Src, Dst, DstIsVolatile);
 return;
   }
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 9b21f428b0af7f5..2f1954fad80f159 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1123,9 +1123,7 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
 if (!CurFnInfo->getReturnInfo().getIndirectByVal()) {
   ReturnValuePointer =
   CreateDefaultAlignTempAlloca(Int8PtrTy, "result.ptr");
-  Builder.CreateStore(Builder.CreatePointerBitCastOrAddrSpaceCast(
-  ReturnValue.getPointer(), Int8PtrTy),
-  ReturnValuePointer);
+  Builder.CreateStore(ReturnValue.getPointer(), ReturnValuePointer);
 }
   } else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::InAlloca &&
  !hasScalarEvaluationKind(CurFnInfo->getReturnType())) {
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 0c89871420bdd3d..f7ef9503aa61033 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -3088,9 +3088,6 @@ void ItaniumCXXABI::EmitThreadLocalInitFuncs(
   CharUnits Align = CGM.getContext().getDeclAlign(VD);
   Val = Builder.CreateAlignedLoad(Var->getValueType(), Val, Align);
 }
-if (Val->getType() != Wrapper->getReturnType())
-  Val = Builder.CreatePointerBitCastOrAddrSpaceCast(
-  Val, Wrapper->getReturnType(), "");
 
 Builder.CreateRet(Val);
   }
diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp
index 3d79f92137abc79..60224d458f6a262 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -137,7 +137,7 @@ llvm::Value *TargetCodeGenInfo::performAddrSpaceCast(
   if (auto *C = dyn_cast(Src))
 return performAddrSpaceCast(CGF.CGM, C, SrcAddr, DestAddr, DestTy);
   // Try to preserve the source's name to make IR more readable.
-  return CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
+  return CGF.Builder.CreateAddrSpaceCast(
   Src, DestTy, Src->hasName() ? Src->getName() + ".ascast" : "");
 }
 
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index c9f243fdb12e404..a32ec9a66fedfa8 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -2138,6 +2138,8 @@ class IRBuilderBase {
 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
   }
 
+  // With opaque pointers enabled, this is same as CreateAddressSpaceCast.
+  // TODO: Replace uses of this method and remove the method itself.
   Value *CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy,
  const Twine &Name = "") {
 if (V->getType() == DestTy)

>From 578bc43ac6bd066052803e76e1f3eb38b9798994 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Thu, 5 Oct 2023 21:46:26 -0400
Subject: [PATCH 2/2] Update comment for CreatePointerBitCastOrAddrSpaceCast

---
 llvm/include/llvm/IR/IRBuilder.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index a32ec9a66fedfa8..a2fab842b1d0355 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -2138,7 +2138,7 @@ class IRBuilderBase {
 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
   }
 
-  // With opaque pointers enabled, this is same as CreateAddressSpaceCast.
+  // With opaque pointers enabled, this can be substituted with 
CreateAddrSpaceCast.
   // TODO: Replace uses of this method a

[clang] [clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast (NFC) (PR #68277)

2023-10-05 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 updated 
https://github.com/llvm/llvm-project/pull/68277

>From 2c3fb032e7fdefa553ed4833bbeed8852eb6a410 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Mon, 2 Oct 2023 12:28:33 -0400
Subject: [PATCH 1/3] [clang] Replace uses of
 CreatePointerBitCastOrAddrSpaceCast (NFC)

With opaque pointers, CreatePointerBitCastOrAddrSpaceCast is same as 
CreateAddrSpaceCast.
Replace or remove uses of CreatePointerBitCastOrAddrSpaceCast.

Opaque pointer cleanup effort.
---
 clang/lib/CodeGen/CGCall.cpp  | 2 +-
 clang/lib/CodeGen/CodeGenFunction.cpp | 4 +---
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 3 ---
 clang/lib/CodeGen/TargetInfo.cpp  | 2 +-
 llvm/include/llvm/IR/IRBuilder.h  | 2 ++
 5 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 93e16575042c4da..b0d1fcd26a5f413 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1376,7 +1376,7 @@ static void CreateCoercedStore(llvm::Value *Src,
   llvm::PointerType *DstPtrTy = llvm::dyn_cast(DstTy);
   if (SrcPtrTy && DstPtrTy &&
   SrcPtrTy->getAddressSpace() != DstPtrTy->getAddressSpace()) {
-Src = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(Src, DstTy);
+Src = CGF.Builder.CreateAddrSpaceCast(Src, DstTy);
 CGF.Builder.CreateStore(Src, Dst, DstIsVolatile);
 return;
   }
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 9b21f428b0af7f5..2f1954fad80f159 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1123,9 +1123,7 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
 if (!CurFnInfo->getReturnInfo().getIndirectByVal()) {
   ReturnValuePointer =
   CreateDefaultAlignTempAlloca(Int8PtrTy, "result.ptr");
-  Builder.CreateStore(Builder.CreatePointerBitCastOrAddrSpaceCast(
-  ReturnValue.getPointer(), Int8PtrTy),
-  ReturnValuePointer);
+  Builder.CreateStore(ReturnValue.getPointer(), ReturnValuePointer);
 }
   } else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::InAlloca &&
  !hasScalarEvaluationKind(CurFnInfo->getReturnType())) {
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 0c89871420bdd3d..f7ef9503aa61033 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -3088,9 +3088,6 @@ void ItaniumCXXABI::EmitThreadLocalInitFuncs(
   CharUnits Align = CGM.getContext().getDeclAlign(VD);
   Val = Builder.CreateAlignedLoad(Var->getValueType(), Val, Align);
 }
-if (Val->getType() != Wrapper->getReturnType())
-  Val = Builder.CreatePointerBitCastOrAddrSpaceCast(
-  Val, Wrapper->getReturnType(), "");
 
 Builder.CreateRet(Val);
   }
diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp
index 3d79f92137abc79..60224d458f6a262 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -137,7 +137,7 @@ llvm::Value *TargetCodeGenInfo::performAddrSpaceCast(
   if (auto *C = dyn_cast(Src))
 return performAddrSpaceCast(CGF.CGM, C, SrcAddr, DestAddr, DestTy);
   // Try to preserve the source's name to make IR more readable.
-  return CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
+  return CGF.Builder.CreateAddrSpaceCast(
   Src, DestTy, Src->hasName() ? Src->getName() + ".ascast" : "");
 }
 
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index c9f243fdb12e404..a32ec9a66fedfa8 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -2138,6 +2138,8 @@ class IRBuilderBase {
 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
   }
 
+  // With opaque pointers enabled, this is same as CreateAddressSpaceCast.
+  // TODO: Replace uses of this method and remove the method itself.
   Value *CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy,
  const Twine &Name = "") {
 if (V->getType() == DestTy)

>From 578bc43ac6bd066052803e76e1f3eb38b9798994 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Thu, 5 Oct 2023 21:46:26 -0400
Subject: [PATCH 2/3] Update comment for CreatePointerBitCastOrAddrSpaceCast

---
 llvm/include/llvm/IR/IRBuilder.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index a32ec9a66fedfa8..a2fab842b1d0355 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -2138,7 +2138,7 @@ class IRBuilderBase {
 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
   }
 
-  // With opaque pointers enabled, this is same as CreateAddressSpaceCast.
+  // With opaque pointers enabled, this can be substituted with 
CreateAddrSpaceCast.
   // TODO: Replace uses of this method a

[clang] ac84ada - [clang] Avoid 'raw_string_ostream::str' (NFC)

2024-06-30 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2024-06-30T10:02:49-05:00
New Revision: ac84ada9a169a72ad136ef05c2c194f594f24a37

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

LOG: [clang] Avoid 'raw_string_ostream::str' (NFC)

Since `raw_string_ostream` doesn't own the string buffer, it is
desirable (in terms of memory safety) for users to directly reference
the string buffer rather than use `raw_string_ostream::str()`.

Work towards TODO comment to remove `raw_string_ostream::str()`.

Added: 


Modified: 
clang/lib/Tooling/Transformer/Stencil.cpp
clang/unittests/AST/MatchVerifier.h
clang/unittests/Interpreter/InterpreterTest.cpp
clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp
clang/unittests/Tooling/ReplacementsYamlTest.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Transformer/Stencil.cpp 
b/clang/lib/Tooling/Transformer/Stencil.cpp
index d91c9e0a20cc1..bc4fa6e36057c 100644
--- a/clang/lib/Tooling/Transformer/Stencil.cpp
+++ b/clang/lib/Tooling/Transformer/Stencil.cpp
@@ -51,7 +51,7 @@ static Error printNode(StringRef Id, const 
MatchFinder::MatchResult &Match,
   if (auto Err = NodeOrErr.takeError())
 return Err;
   NodeOrErr->print(Os, PrintingPolicy(Match.Context->getLangOpts()));
-  *Result += Os.str();
+  *Result += Output;
   return Error::success();
 }
 
@@ -371,7 +371,7 @@ class SelectBoundStencil : public 
clang::transformer::StencilInterface {
   Stream << ", " << DefaultStencil->toString();
 }
 Stream << ")";
-return Stream.str();
+return Buffer;
   }
 
 private:

diff  --git a/clang/unittests/AST/MatchVerifier.h 
b/clang/unittests/AST/MatchVerifier.h
index da1e351da4a09..60bb4a8716ae8 100644
--- a/clang/unittests/AST/MatchVerifier.h
+++ b/clang/unittests/AST/MatchVerifier.h
@@ -209,7 +209,7 @@ class LocationVerifier : public MatchVerifier {
   << ">, found <";
   Loc.print(Msg, *Result.SourceManager);
   Msg << '>';
-  this->setFailure(Msg.str());
+  this->setFailure(MsgStr);
 }
   }
 
@@ -256,7 +256,7 @@ class RangeVerifier : public MatchVerifier {
   Msg << '-';
   End.print(Msg, *Result.SourceManager);
   Msg << '>';
-  this->setFailure(Msg.str());
+  this->setFailure(MsgStr);
 }
   }
 
@@ -282,12 +282,12 @@ class DumpVerifier : public MatchVerifier {
 llvm::raw_string_ostream Dump(DumpStr);
 Node.dump(Dump, *Result.Context);
 
-if (Dump.str().find(ExpectSubstring) == std::string::npos) {
+if (DumpStr.find(ExpectSubstring) == std::string::npos) {
   std::string MsgStr;
   llvm::raw_string_ostream Msg(MsgStr);
   Msg << "Expected dump substring <" << ExpectSubstring << ">, found <"
-  << Dump.str() << '>';
-  this->setFailure(Msg.str());
+  << DumpStr << '>';
+  this->setFailure(MsgStr);
 }
   }
 
@@ -309,12 +309,12 @@ class PrintVerifier : public MatchVerifier {
 llvm::raw_string_ostream Print(PrintStr);
 Node.print(Print, Result.Context->getPrintingPolicy());
 
-if (Print.str() != ExpectString) {
+if (PrintStr != ExpectString) {
   std::string MsgStr;
   llvm::raw_string_ostream Msg(MsgStr);
   Msg << "Expected pretty print <" << ExpectString << ">, found <"
-  << Print.str() << '>';
-  this->setFailure(Msg.str());
+  << PrintStr << '>';
+  this->setFailure(MsgStr);
 }
   }
 

diff  --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index bbd854149d5f5..29c5ead60b81e 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -101,7 +101,7 @@ TEST_F(InterpreterTest, Errors) {
   auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
   auto Err = Interp->Parse("intentional_error v1 = 42; ").takeError();
   using ::testing::HasSubstr;
-  EXPECT_THAT(DiagnosticsOS.str(),
+  EXPECT_THAT(DiagnosticOutput,
   HasSubstr("error: unknown type name 'intentional_error'"));
   EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
 
@@ -186,7 +186,7 @@ static std::string MangleName(NamedDecl *ND) {
   std::string mangledName;
   llvm::raw_string_ostream RawStr(mangledName);
   MangleC->mangleName(ND, RawStr);
-  return RawStr.str();
+  return mangledName;
 }
 
 TEST_F(InterpreterTest, FindMangledNameSymbol) {

diff  --git 
a/clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp 
b/clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp
index 274f275ea66a9..cd4bf0eb7bd5a 100644
--- a/clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp
+++ b/clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp
@@ -22,7 +22,7 @@ class DeductionGuideVisitor
 std::string Storage;
 ll

[clang] 0856064 - [clang][StaticAnalyzer] Avoid 'raw_string_ostream::str' (NFC)

2024-07-02 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2024-07-02T19:52:09-05:00
New Revision: 0856064ea219d029e7d2c4f68bb88196fe647f6b

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

LOG: [clang][StaticAnalyzer] Avoid 'raw_string_ostream::str' (NFC)

Since `raw_string_ostream` doesn't own the string buffer, it is
desirable (in terms of memory safety) for users to directly reference
the string buffer rather than use `raw_string_ostream::str()`.

Work towards TODO comment to remove `raw_string_ostream::str()`.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp

clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
clang/lib/StaticAnalyzer/Core/SVals.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
index b4390f0b85bbe..9d3aeff465ca1 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
@@ -247,8 +247,8 @@ void ObjCDeallocChecker::checkASTDecl(const 
ObjCImplementationDecl *D,
 PathDiagnosticLocation DLoc =
 PathDiagnosticLocation::createBegin(D, BR.getSourceManager());
 
-BR.EmitBasicReport(D, this, Name, categories::CoreFoundationObjectiveC,
-   OS.str(), DLoc);
+BR.EmitBasicReport(D, this, Name, categories::CoreFoundationObjectiveC, 
Buf,
+   DLoc);
 return;
   }
 }
@@ -585,7 +585,7 @@ void 
ObjCDeallocChecker::diagnoseMissingReleases(CheckerContext &C) const {
   " before '[super dealloc]'";
 
 auto BR = std::make_unique(MissingReleaseBugType,
-   OS.str(), ErrNode);
+   Buf, ErrNode);
 C.emitReport(std::move(BR));
   }
 
@@ -706,8 +706,8 @@ bool ObjCDeallocChecker::diagnoseExtraRelease(SymbolRef 
ReleasedValue,
 OS <<  " property but was released in 'dealloc'";
   }
 
-  auto BR = std::make_unique(ExtraReleaseBugType,
- OS.str(), ErrNode);
+  auto BR = std::make_unique(ExtraReleaseBugType, Buf,
+ ErrNode);
   BR->addRange(M.getOriginExpr()->getSourceRange());
 
   C.emitReport(std::move(BR));
@@ -749,7 +749,7 @@ bool ObjCDeallocChecker::diagnoseMistakenDealloc(SymbolRef 
DeallocedValue,
  << "' should be released rather than deallocated";
 
   auto BR = std::make_unique(MistakenDeallocBugType,
- OS.str(), ErrNode);
+ Buf, ErrNode);
   BR->addRange(M.getOriginExpr()->getSourceRange());
 
   C.emitReport(std::move(BR));

diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
index 086c3e5e49b77..f73c9007c1838 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
@@ -411,11 +411,11 @@ annotateConsumedSummaryMismatch(const ExplodedNode *N,
 }
   }
 
-  if (os.str().empty())
+  if (sbuf.empty())
 return nullptr;
 
   PathDiagnosticLocation L = PathDiagnosticLocation::create(CallExitLoc, SM);
-  return std::make_shared(L, os.str());
+  return std::make_shared(L, sbuf);
 }
 
 /// Annotate the parameter at the analysis entry point.
@@ -446,7 +446,7 @@ annotateStartParameter(const ExplodedNode *N, SymbolRef Sym,
 assert(CurrT->getCount() == 0);
 os << "0";
   }
-  return std::make_shared(L, os.str());
+  return std::make_shared(L, s);
 }
 
 PathDiagnosticPieceRef
@@ -493,7 +493,7 @@ RefCountReportVisitor::VisitNode(const ExplodedNode *N, 
BugReporterContext &BRC,
   if (PrevT && IsFreeUnowned && CurrV.isNotOwned() && PrevT->isOwned()) {
 os << "Object is now not exclusively owned";
 auto Pos = PathDiagnosticLocation::create(N->getLocation(), SM);
-return std::make_shared(Pos, os.str());
+return std::make_shared(Pos, sbuf);
   }
 
   // This is the allocation site since the previous node had no bindings
@@ -535,7 +535,7 @@ RefCountReportVisitor::VisitNode(const ExplodedNode *N, 
BugReporterContext &BRC,
 }
 
 PathDiagnosticLocation Pos(S, SM, N->getLocationContext());
-return std::make_shared(Pos, os.str());
+return std::make_shared(Pos, sbuf);
   }
 
   // Gather up the effects that were performed on the object at this
@@ -582,13 +582,13 @@ RefCountReportVisitor::VisitNode(const ExplodedNo

[clang] 9e21174 - [clang] Avoid 'raw_string_ostream::str' (NFC)

2024-07-04 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2024-07-04T21:59:19-05:00
New Revision: 9e211744b82a72e08c137f75b1c671713e2891af

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

LOG: [clang] Avoid 'raw_string_ostream::str' (NFC)

Since `raw_string_ostream` doesn't own the string buffer, it is
desirable (in terms of memory safety) for users to directly reference
the string buffer rather than use `raw_string_ostream::str()`.

Work towards TODO item to remove `raw_string_ostream::str()`.

Added: 


Modified: 
clang/lib/InstallAPI/DiagnosticBuilderWrappers.cpp
clang/unittests/Frontend/CompilerInstanceTest.cpp
clang/unittests/Tooling/LexicallyOrderedRecursiveASTVisitorTest.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/lib/InstallAPI/DiagnosticBuilderWrappers.cpp 
b/clang/lib/InstallAPI/DiagnosticBuilderWrappers.cpp
index cc252d51e3b67..c8d07f229902b 100644
--- a/clang/lib/InstallAPI/DiagnosticBuilderWrappers.cpp
+++ b/clang/lib/InstallAPI/DiagnosticBuilderWrappers.cpp
@@ -48,7 +48,7 @@ const DiagnosticBuilder &operator<<(const DiagnosticBuilder 
&DB,
   Stream << PV.second.getAsString();
   });
   Stream << " ]";
-  DB.AddString(Stream.str());
+  DB.AddString(PlatformAsString);
   return DB;
 }
 
@@ -91,7 +91,7 @@ const DiagnosticBuilder &operator<<(const DiagnosticBuilder 
&DB,
   std::string VersionString;
   raw_string_ostream OS(VersionString);
   OS << Version;
-  DB.AddString(OS.str());
+  DB.AddString(VersionString);
   return DB;
 }
 
@@ -102,7 +102,7 @@ operator<<(const clang::DiagnosticBuilder &DB,
   raw_string_ostream OS(IFAsString);
 
   OS << LibAttr.getKey() << " [ " << LibAttr.getValue() << " ]";
-  DB.AddString(OS.str());
+  DB.AddString(IFAsString);
   return DB;
 }
 

diff  --git a/clang/unittests/Frontend/CompilerInstanceTest.cpp 
b/clang/unittests/Frontend/CompilerInstanceTest.cpp
index a28d72e7d9531..8bc705dd21993 100644
--- a/clang/unittests/Frontend/CompilerInstanceTest.cpp
+++ b/clang/unittests/Frontend/CompilerInstanceTest.cpp
@@ -91,7 +91,7 @@ TEST(CompilerInstance, 
AllowDiagnosticLogWithUnownedDiagnosticConsumer) {
   DiagOpts, DiagPrinter.get(), /*ShouldOwnClient=*/false);
 
   Diags->Report(diag::err_expected) << "no crash";
-  ASSERT_EQ(DiagnosticsOS.str(), "error: expected no crash\n");
+  ASSERT_EQ(DiagnosticOutput, "error: expected no crash\n");
 }
 
 } // anonymous namespace

diff  --git 
a/clang/unittests/Tooling/LexicallyOrderedRecursiveASTVisitorTest.cpp 
b/clang/unittests/Tooling/LexicallyOrderedRecursiveASTVisitorTest.cpp
index 38079f706f398..5d16595aec801 100644
--- a/clang/unittests/Tooling/LexicallyOrderedRecursiveASTVisitorTest.cpp
+++ b/clang/unittests/Tooling/LexicallyOrderedRecursiveASTVisitorTest.cpp
@@ -87,7 +87,7 @@ bool LexicallyOrderedDeclVisitor::VisitNamedDecl(const 
NamedDecl *D) {
   }
   if (EmitDeclIndices)
 OS << "@" << Index++;
-  Matcher.match(OS.str(), D);
+  Matcher.match(Path, D);
   return true;
 }
 
@@ -96,7 +96,7 @@ bool LexicallyOrderedDeclVisitor::VisitDeclRefExpr(const 
DeclRefExpr *D) {
   llvm::raw_string_ostream OS(Name);
   if (EmitStmtIndices)
 OS << "@" << Index++;
-  Matcher.match(OS.str(), D);
+  Matcher.match(Name, D);
   return true;
 }
 

diff  --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 7bf6091e63d18..1f83440680330 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -4786,7 +4786,7 @@ void EmitClangAttrParsedAttrImpl(RecordKeeper &Records, 
raw_ostream &OS) {
   // Write out the declaration merging check logic.
   OS << "static bool DiagnoseMutualExclusions(Sema &S, const NamedDecl *D, "
  << "const Attr *A) {\n";
-  OS << MergeDeclOS.str();
+  OS << DeclMergeChecks;
   OS << "  return true;\n";
   OS << "}\n\n";
 
@@ -4796,7 +4796,7 @@ void EmitClangAttrParsedAttrImpl(RecordKeeper &Records, 
raw_ostream &OS) {
   OS << "static bool DiagnoseMutualExclusions(Sema &S, "
  << "const SmallVectorImpl &C) {\n";
   OS << "  for (const Attr *A : C) {\n";
-  OS << MergeStmtOS.str();
+  OS << StmtMergeChecks;
   OS << "  }\n";
   OS << "  return true;\n";
   OS << "}\n\n";
@@ -4939,7 +4939,7 @@ void EmitClangAttrTextNodeDump(RecordKeeper &Records, 
raw_ostream &OS) {
   if (!Args.empty())
 OS << "const auto *SA = cast<" << R.getName()
<< "Attr>(A); (void)SA;\n";
-  OS << SS.str();
+  OS << FunctionContent;
   OS << "  }\n";
 }
   }
@@ -4968,7 +4968,7 @@ void EmitClangAttrNodeTraverse(RecordKeeper &Records, 
raw_ostream &OS) {
   if (!Args.empty())
 OS << "const auto *SA = cast<" << R.getName()
<< "Attr>(A); (void)SA;\n";
-  OS << SS.str();
+  OS << FunctionContent;

[clang] ccc0b66 - [clang] Avoid 'raw_string_ostream::str' (NFC)

2024-07-05 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2024-07-05T06:42:43-05:00
New Revision: ccc0b66d6971b64175b4e99c6d5baaa2830c4208

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

LOG: [clang] Avoid 'raw_string_ostream::str' (NFC)

Since `raw_string_ostream` doesn't own the string buffer, it is
desirable (in terms of memory safety) for users to directly reference
the string buffer rather than use `raw_string_ostream::str()`.

Work towards TODO item to remove `raw_string_ostream::str()`.

p.s. also remove some unneeded/dead code.

Added: 


Modified: 
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/Driver/ToolChains/Darwin.cpp
clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
clang/lib/Sema/SemaCodeComplete.cpp

Removed: 




diff  --git a/clang/lib/AST/JSONNodeDumper.cpp 
b/clang/lib/AST/JSONNodeDumper.cpp
index 3bbb3a905e9b91..339477dc65f0f7 100644
--- a/clang/lib/AST/JSONNodeDumper.cpp
+++ b/clang/lib/AST/JSONNodeDumper.cpp
@@ -237,7 +237,7 @@ void JSONNodeDumper::Visit(const APValue &Value, QualType 
Ty) {
   std::string Str;
   llvm::raw_string_ostream OS(Str);
   Value.printPretty(OS, Ctx, Ty);
-  JOS.attribute("value", OS.str());
+  JOS.attribute("value", Str);
 }
 
 void JSONNodeDumper::Visit(const ConceptReference *CR) {
@@ -802,7 +802,7 @@ void JSONNodeDumper::VisitTemplateSpecializationType(
   std::string Str;
   llvm::raw_string_ostream OS(Str);
   TST->getTemplateName().print(OS, PrintPolicy);
-  JOS.attribute("templateName", OS.str());
+  JOS.attribute("templateName", Str);
 }
 
 void JSONNodeDumper::VisitInjectedClassNameType(
@@ -824,7 +824,7 @@ void JSONNodeDumper::VisitElaboratedType(const 
ElaboratedType *ET) {
 std::string Str;
 llvm::raw_string_ostream OS(Str);
 NNS->print(OS, PrintPolicy, /*ResolveTemplateArgs*/ true);
-JOS.attribute("qualifier", OS.str());
+JOS.attribute("qualifier", Str);
   }
   if (const TagDecl *TD = ET->getOwnedTagDecl())
 JOS.attribute("ownedTagDecl", createBareDeclRef(TD));
@@ -1246,7 +1246,7 @@ void JSONNodeDumper::VisitObjCMessageExpr(const 
ObjCMessageExpr *OME) {
   llvm::raw_string_ostream OS(Str);
 
   OME->getSelector().print(OS);
-  JOS.attribute("selector", OS.str());
+  JOS.attribute("selector", Str);
 
   switch (OME->getReceiverKind()) {
   case ObjCMessageExpr::Instance:
@@ -1277,7 +1277,7 @@ void JSONNodeDumper::VisitObjCBoxedExpr(const 
ObjCBoxedExpr *OBE) {
 llvm::raw_string_ostream OS(Str);
 
 MD->getSelector().print(OS);
-JOS.attribute("selector", OS.str());
+JOS.attribute("selector", Str);
   }
 }
 
@@ -1286,7 +1286,7 @@ void JSONNodeDumper::VisitObjCSelectorExpr(const 
ObjCSelectorExpr *OSE) {
   llvm::raw_string_ostream OS(Str);
 
   OSE->getSelector().print(OS);
-  JOS.attribute("selector", OS.str());
+  JOS.attribute("selector", Str);
 }
 
 void JSONNodeDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *OPE) {
@@ -1634,7 +1634,7 @@ void JSONNodeDumper::VisitStringLiteral(const 
StringLiteral *SL) {
   std::string Buffer;
   llvm::raw_string_ostream SS(Buffer);
   SL->outputString(SS);
-  JOS.attribute("value", SS.str());
+  JOS.attribute("value", Buffer);
 }
 void JSONNodeDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *BLE) {
   JOS.attribute("value", BLE->getValue());

diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 64ab328a6d25f6..f354b0974d5f27 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -3029,7 +3029,7 @@ void Darwin::addClangCC1ASTargetOptions(
   std::string Arg;
   llvm::raw_string_ostream OS(Arg);
   OS << "-target-sdk-version=" << V;
-  CC1ASArgs.push_back(Args.MakeArgString(OS.str()));
+  CC1ASArgs.push_back(Args.MakeArgString(Arg));
 };
 
 if (isTargetMacCatalyst()) {
@@ -3052,7 +3052,7 @@ void Darwin::addClangCC1ASTargetOptions(
 std::string Arg;
 llvm::raw_string_ostream OS(Arg);
 OS << "-darwin-target-variant-sdk-version=" << SDKInfo->getVersion();
-CC1ASArgs.push_back(Args.MakeArgString(OS.str()));
+CC1ASArgs.push_back(Args.MakeArgString(Arg));
   } else if (const auto *MacOStoMacCatalystMapping =
  SDKInfo->getVersionMapping(
  DarwinSDKInfo::OSEnvPair::macOStoMacCatalystPair())) {
@@ -3063,7 +3063,7 @@ void Darwin::addClangCC1ASTargetOptions(
   std::string Arg;
   llvm::raw_string_ostream OS(Arg);
   OS << "-darwin-target-variant-sdk-version=" << *SDKVersion;
-  CC1ASArgs.push_back(Args.MakeArgString(OS.str()));
+  CC1ASArgs.push_back(Args.MakeArgString(Arg));
 }
   }
 }

diff  --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp 
b/clang/lib/Frontend/Rewrite/RewriteModernObj

[clang] [Clang] Remove unnecessary copy (PR #97902)

2024-07-06 Thread Youngsuk Kim via cfe-commits


@@ -1551,7 +1551,7 @@ ASTNodeImporter::VisitCountAttributedType(const 
CountAttributedType *T) {
   Expr *CountExpr = importChecked(Err, T->getCountExpr());
 
   SmallVector CoupledDecls;
-  for (auto TI : T->dependent_decls()) {
+  for (const TypeCoupledDeclRefInfo &TI : T->dependent_decls()) {

JOE1994 wrote:

```suggestion
  for (const auto &TI : T->dependent_decls()) {
```

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


[clang] [Clang][Sema] Warn unused cxx vardecl which entirely consists condition expr of if/while/for construct (PR #87348)

2024-04-04 Thread Youngsuk Kim via cfe-commits

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


[clang] 66190af - [Clang] ReleaseNote item for 9dab2e3064a2ad4d5ce65832d605787dc394cb72

2024-04-04 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2024-04-04T20:49:45-05:00
New Revision: 66190af7350df7edb03f7ebb8ac11065bb07e22c

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

LOG: [Clang] ReleaseNote item for 9dab2e3064a2ad4d5ce65832d605787dc394cb72

Add release item which was omitted at the time.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 92032c02644b82..4e87bd02736d41 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -334,6 +334,9 @@ Improvements to Clang's diagnostics
 - Clang now emits ``unused argument`` warning when the -fmodule-output flag is 
used
   with an input that is not of type c++-module.
 
+- Clang emits a ``-Wreturn-stack-address`` warning if a function returns a 
pointer or
+  reference to a struct literal. Fixes #GH8678
+
 - Clang emits a ``-Wunused-but-set-variable`` warning on C++ variables whose 
declaration
   (with initializer) entirely consist the condition expression of a 
if/while/for construct
   but are not actually used in the body of the if/while/for construct. Fixes 
#GH41447



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


[clang] Assume a for-in loop is in bounds and cannot overflow (PR #94883)

2024-06-09 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

Why did you close this PR so soon after creating it?

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


[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-28 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 updated 
https://github.com/llvm/llvm-project/pull/93394

>From 00c93043fca8f8a1f20634ea1b281c60926bd571 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Sat, 25 May 2024 20:42:43 -0500
Subject: [PATCH 1/5] [clang][Sema] Don't emit 'declared here' note for builtin
 functions with no decl in source

Fixes #93369
---
 clang/lib/Sema/SemaLookup.cpp   | 10 ++
 clang/test/SemaCXX/invalid-if-constexpr.cpp |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index ef0a655b631ab..348f9e5b8f530 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -5897,6 +5897,16 @@ void Sema::diagnoseTypo(const TypoCorrection &Correction,
 
   NamedDecl *ChosenDecl =
   Correction.isKeyword() ? nullptr : Correction.getFoundDecl();
+
+  // For builtin functions which aren't declared anywhere in source,
+  // don't emit the "declared here" note.
+  if (auto *FD = dyn_cast_or_null(ChosenDecl);
+  FD && FD->getBuiltinID() &&
+  PrevNote.getDiagID() == diag::note_previous_decl &&
+  Correction.getCorrectionRange().getBegin() == FD->getBeginLoc()) {
+ChosenDecl = nullptr;
+  }
+
   if (PrevNote.getDiagID() && ChosenDecl)
 Diag(ChosenDecl->getLocation(), PrevNote)
   << CorrectedQuotedStr << (ErrorRecovery ? FixItHint() : FixTypo);
diff --git a/clang/test/SemaCXX/invalid-if-constexpr.cpp 
b/clang/test/SemaCXX/invalid-if-constexpr.cpp
index 7643c47488f05..16d422880e8a9 100644
--- a/clang/test/SemaCXX/invalid-if-constexpr.cpp
+++ b/clang/test/SemaCXX/invalid-if-constexpr.cpp
@@ -5,7 +5,7 @@ void similar() { // expected-note {{'similar' declared here}}
   if constexpr (similer<>) {} // expected-error {{use of undeclared identifier 
'similer'; did you mean 'similar'?}}
 }
 void a() { if constexpr (__adl_swap<>) {}} // expected-error{{use of 
undeclared identifier '__adl_swap'; did you mean '__sync_swap'?}} \
-   // expected-note {{'__sync_swap' 
declared here}}
+   // not-expected-note 
{{'__sync_swap' declared here}}
 
 int AA() { return true;} // expected-note {{'AA' declared here}}
 

>From 42bbff26459b71e9d77c4d907703930e12db8958 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Sun, 26 May 2024 05:53:03 -0400
Subject: [PATCH 2/5] Use dyn_cast_if_present

Co-authored-by: Timm Baeder 
---
 clang/lib/Sema/SemaLookup.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 348f9e5b8f530..be6ea20a956a3 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -5900,7 +5900,7 @@ void Sema::diagnoseTypo(const TypoCorrection &Correction,
 
   // For builtin functions which aren't declared anywhere in source,
   // don't emit the "declared here" note.
-  if (auto *FD = dyn_cast_or_null(ChosenDecl);
+  if (const auto *FD = dyn_cast_if_present(ChosenDecl);
   FD && FD->getBuiltinID() &&
   PrevNote.getDiagID() == diag::note_previous_decl &&
   Correction.getCorrectionRange().getBegin() == FD->getBeginLoc()) {

>From e4f190be4f59dec78c8a184d9603ac8856da3900 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Sun, 26 May 2024 10:28:02 -0500
Subject: [PATCH 3/5] Add dedicated test

---
 clang/test/SemaCXX/invalid-if-constexpr.cpp | 1 -
 clang/test/SemaCXX/typo-correction-builtin-func.cpp | 8 
 2 files changed, 8 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/typo-correction-builtin-func.cpp

diff --git a/clang/test/SemaCXX/invalid-if-constexpr.cpp 
b/clang/test/SemaCXX/invalid-if-constexpr.cpp
index 16d422880e8a9..1fe0bc3415c84 100644
--- a/clang/test/SemaCXX/invalid-if-constexpr.cpp
+++ b/clang/test/SemaCXX/invalid-if-constexpr.cpp
@@ -5,7 +5,6 @@ void similar() { // expected-note {{'similar' declared here}}
   if constexpr (similer<>) {} // expected-error {{use of undeclared identifier 
'similer'; did you mean 'similar'?}}
 }
 void a() { if constexpr (__adl_swap<>) {}} // expected-error{{use of 
undeclared identifier '__adl_swap'; did you mean '__sync_swap'?}} \
-   // not-expected-note 
{{'__sync_swap' declared here}}
 
 int AA() { return true;} // expected-note {{'AA' declared here}}
 
diff --git a/clang/test/SemaCXX/typo-correction-builtin-func.cpp 
b/clang/test/SemaCXX/typo-correction-builtin-func.cpp
new file mode 100644
index 0..8d369034d1be3
--- /dev/null
+++ b/clang/test/SemaCXX/typo-correction-builtin-func.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// Test that clang does not emit 'declared here' note for builtin functions 
that don't have a declaration in source.
+
+void t0() {
+  constexpr float A = __builtin_isinfinity(); // expected-error {{use of 
undeclared identifier '__builtin_isinfinity'; did you mean 
'__builtin_isfinite'?}}
+

[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-28 Thread Youngsuk Kim via cfe-commits

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


[clang] [clang] ``README.txt``: Replace the link to the old bug tracker with the new one. (PR #93878)

2024-05-30 Thread Youngsuk Kim via cfe-commits

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


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


[clang] [clang] ``README.txt``: Replace the link to the old bug tracker with the new one. (PR #93878)

2024-05-31 Thread Youngsuk Kim via cfe-commits

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


[clang] [clang][driver] add pointer qualifier to auto type (PR #91874)

2024-06-03 Thread Youngsuk Kim via cfe-commits

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


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


[clang] [clang][driver] add pointer qualifier to auto type (PR #91874)

2024-06-03 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 requested changes to this pull request.

The 3 updated items seem to be iterators and not pointers.

I think [the coding standard 
item](https://llvm.org/docs/CodingStandards.html#beware-unnecessary-copies-with-auto)
 doesn't apply here.

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


[clang] [clang] Add method 'backupStr' to ASTContext (PR #99417)

2024-07-23 Thread Youngsuk Kim via cfe-commits

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


[clang] 1cd6359 - [clang][ASTReaderStmt] Use helper function 'saveStrToCtx' (NFC)

2024-07-16 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2024-07-16T10:06:08-05:00
New Revision: 1cd6359f39ab7fa55f00086c322bc183adb583bc

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

LOG: [clang][ASTReaderStmt] Use helper function 'saveStrToCtx' (NFC)

Added: 


Modified: 
clang/lib/Serialization/ASTReaderStmt.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReaderStmt.cpp 
b/clang/lib/Serialization/ASTReaderStmt.cpp
index 7a3b81fc358ac..6955b42f14e06 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -921,14 +921,10 @@ void ASTStmtReader::VisitRequiresExpr(RequiresExpr *E) {
   case concepts::Requirement::RK_Nested: {
 bool HasInvalidConstraint = Record.readInt();
 if (HasInvalidConstraint) {
-  std::string InvalidConstraint = Record.readString();
-  char *InvalidConstraintBuf =
-  new (Record.getContext()) char[InvalidConstraint.size()];
-  std::copy(InvalidConstraint.begin(), InvalidConstraint.end(),
-InvalidConstraintBuf);
+  StringRef InvalidConstraint =
+  saveStrToCtx(Record.readString(), Record.getContext());
   R = new (Record.getContext()) concepts::NestedRequirement(
-  Record.getContext(),
-  StringRef(InvalidConstraintBuf, InvalidConstraint.size()),
+  Record.getContext(), InvalidConstraint,
   readConstraintSatisfaction(Record));
   break;
 }



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


[clang] [Clang] Remove unnecessary copy (PR #97902)

2024-07-16 Thread Youngsuk Kim via cfe-commits


@@ -1551,7 +1551,7 @@ ASTNodeImporter::VisitCountAttributedType(const 
CountAttributedType *T) {
   Expr *CountExpr = importChecked(Err, T->getCountExpr());
 
   SmallVector CoupledDecls;
-  for (auto TI : T->dependent_decls()) {
+  for (const TypeCoupledDeclRefInfo &TI : T->dependent_decls()) {

JOE1994 wrote:

Please feel free to apply a commit to make the type name explicit
(the `auto` suggestion was out of my personal preference for brevity).

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


[clang] [Clang] Remove unnecessary copy (PR #97902)

2024-07-16 Thread Youngsuk Kim via cfe-commits

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


[clang] [clang] Add method 'backupStr' to ASTContext (PR #99417)

2024-07-17 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 created 
https://github.com/llvm/llvm-project/pull/99417

Method 'backupStr' extracts common code of manually allocating memory with 
ASTContext to hold a copy of a string's contents.

>From a2c89a383b340c1da61c6c32790f4cd03976c3a0 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Wed, 17 Jul 2024 19:21:16 -0500
Subject: [PATCH] [clang] Add method 'backupStr' to ASTContext

Method 'backupStr' extracts common code of manually allocating memory with
ASTContext to hold a copy of a string's contents.
---
 clang/include/clang/AST/ASTContext.h   |  6 
 clang/lib/AST/ASTConcept.cpp   |  6 ++--
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 31 ---
 clang/lib/Serialization/ASTReaderStmt.cpp  | 36 --
 4 files changed, 33 insertions(+), 46 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 608bd90fcc3ff..50a1659b90388 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -738,6 +738,12 @@ class ASTContext : public RefCountedBase {
   }
   void Deallocate(void *Ptr) const {}
 
+  llvm::StringRef backupStr(llvm::StringRef S) const {
+char *Buf = new (*this) char[S.size()];
+std::copy(S.begin(), S.end(), Buf);
+return llvm::StringRef(Buf, S.size());
+  }
+
   /// Allocates a \c DeclListNode or returns one from the \c ListNodeFreeList
   /// pool.
   DeclListNode *AllocateDeclListNode(clang::NamedDecl *ND) {
diff --git a/clang/lib/AST/ASTConcept.cpp b/clang/lib/AST/ASTConcept.cpp
index 95e7ac1a3d775..d8efbe44dbecb 100644
--- a/clang/lib/AST/ASTConcept.cpp
+++ b/clang/lib/AST/ASTConcept.cpp
@@ -28,11 +28,9 @@ CreateUnsatisfiedConstraintRecord(const ASTContext &C,
   else {
 auto &SubstitutionDiagnostic =
 *Detail.get *>();
-unsigned MessageSize = SubstitutionDiagnostic.second.size();
-char *Mem = new (C) char[MessageSize];
-memcpy(Mem, SubstitutionDiagnostic.second.data(), MessageSize);
+StringRef Message = C.backupStr(SubstitutionDiagnostic.second);
 auto *NewSubstDiag = new (C) std::pair(
-SubstitutionDiagnostic.first, StringRef(Mem, MessageSize));
+SubstitutionDiagnostic.first, Message);
 new (TrailingObject) UnsatisfiedConstraintRecord(NewSubstDiag);
   }
 }
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a7bc6749c5852..e73fced86deeb 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2576,16 +2576,12 @@ createSubstDiag(Sema &S, TemplateDeductionInfo &Info,
   } else {
 ErrorLoc = Info.getLocation();
   }
-  char *MessageBuf = new (S.Context) char[Message.size()];
-  std::copy(Message.begin(), Message.end(), MessageBuf);
   SmallString<128> Entity;
   llvm::raw_svector_ostream OS(Entity);
   Printer(OS);
-  char *EntityBuf = new (S.Context) char[Entity.size()];
-  std::copy(Entity.begin(), Entity.end(), EntityBuf);
-  return new (S.Context) concepts::Requirement::SubstitutionDiagnostic{
-  StringRef(EntityBuf, Entity.size()), ErrorLoc,
-  StringRef(MessageBuf, Message.size())};
+  const ASTContext &C = S.Context;
+  return new (C) concepts::Requirement::SubstitutionDiagnostic{
+  C.backupStr(Entity), ErrorLoc, C.backupStr(Message)};
 }
 
 concepts::Requirement::SubstitutionDiagnostic *
@@ -2594,10 +2590,9 @@ concepts::createSubstDiagAt(Sema &S, SourceLocation 
Location,
   SmallString<128> Entity;
   llvm::raw_svector_ostream OS(Entity);
   Printer(OS);
-  char *EntityBuf = new (S.Context) char[Entity.size()];
-  llvm::copy(Entity, EntityBuf);
-  return new (S.Context) concepts::Requirement::SubstitutionDiagnostic{
-  /*SubstitutedEntity=*/StringRef(EntityBuf, Entity.size()),
+  const ASTContext &C = S.Context;
+  return new (C) concepts::Requirement::SubstitutionDiagnostic{
+  /*SubstitutedEntity=*/C.backupStr(Entity),
   /*DiagLoc=*/Location, /*DiagMessage=*/StringRef()};
 }
 
@@ -2773,23 +2768,21 @@ TemplateInstantiator::TransformNestedRequirement(
 assert(!Trap.hasErrorOccurred() && "Substitution failures must be handled "
"by CheckConstraintSatisfaction.");
   }
+  ASTContext &C = SemaRef.Context;
   if (TransConstraint.isUsable() &&
   TransConstraint.get()->isInstantiationDependent())
-return new (SemaRef.Context)
-concepts::NestedRequirement(TransConstraint.get());
+return new (C) concepts::NestedRequirement(TransConstraint.get());
   if (TransConstraint.isInvalid() || !TransConstraint.get() ||
   Satisfaction.HasSubstitutionFailure()) {
 SmallString<128> Entity;
 llvm::raw_svector_ostream OS(Entity);
 Req->getConstraintExpr()->printPretty(OS, nullptr,
   SemaRef.getPrintingPolicy());
-char *EntityBuf = new (SemaRef.Context) char[Entity.size()];
-std::copy(Entity.begin(), Entity.end(), EntityBuf);

[clang] [clang] Add method 'backupStr' to ASTContext (PR #99417)

2024-07-18 Thread Youngsuk Kim via cfe-commits

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


[clang] [clang][Sema] Re-use existing BinaryOperator if possible (PR #90625)

2024-04-30 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 created 
https://github.com/llvm/llvm-project/pull/90625

First round of Sema checks were run at initial parsing step. Creating a new 
BinaryOperator instance (with the re-built LHS or RHS) will trigger another 
round of Sema checks, which can lead to duplicate diagnostic warning messages.

All we want here is to replace the LHS or RHS with a NonOdrUse version. Don't 
create a new BinaryOperator, but simply replace the LHS or RHS of the given 
BinaryOperator.

Fixes #45783

>From 24eb4db70e296d6454bac4c84a5bbc47e638876f Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Tue, 30 Apr 2024 11:18:15 -0500
Subject: [PATCH] [clang][Sema] Re-use existing BinaryOperator if possible

First round of Sema checks were run at initial parsing step. Creating a new
BinaryOperator instance (with the re-built LHS or RHS) will trigger another
round of Sema checks, which can lead to duplicate diagnostic warning messages.

All we want here is to replace the LHS or RHS with a NonOdrUse version. Don't
create a new BinaryOperator, but simply replace the LHS or RHS of the given
BinaryOperator.

Fixes #45783
---
 clang/lib/Sema/SemaExpr.cpp  | 7 +++
 clang/test/CXX/drs/dr7xx.cpp | 2 --
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 50f92c496a539a..27733cd857d964 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -19707,18 +19707,17 @@ static ExprResult 
rebuildPotentialResultsAsNonOdrUsed(Sema &S, Expr *E,
   ExprResult Sub = Rebuild(LHS);
   if (!Sub.isUsable())
 return Sub;
-  LHS = Sub.get();
+  BO->setLHS(Sub.get());
 //   -- If e is a comma expression, ...
 } else if (BO->getOpcode() == BO_Comma) {
   ExprResult Sub = Rebuild(RHS);
   if (!Sub.isUsable())
 return Sub;
-  RHS = Sub.get();
+  BO->setRHS(Sub.get());
 } else {
   break;
 }
-return S.BuildBinOp(nullptr, BO->getOperatorLoc(), BO->getOpcode(),
-LHS, RHS);
+return ExprResult(BO);
   }
 
   //   -- If e has the form (e1)...
diff --git a/clang/test/CXX/drs/dr7xx.cpp b/clang/test/CXX/drs/dr7xx.cpp
index 69ee6d6d4e6ae0..0300dae08d6d31 100644
--- a/clang/test/CXX/drs/dr7xx.cpp
+++ b/clang/test/CXX/drs/dr7xx.cpp
@@ -28,10 +28,8 @@ namespace cwg712 { // cwg712: partial
 use(a);
 use((a));
 use(cond ? a : a);
-// FIXME: should only warn once
 use((cond, a));
 // expected-warning@-1 {{left operand of comma operator has no effect}}
-// expected-warning@-2 {{left operand of comma operator has no effect}}
 
 (void)a;
 // expected-error@-1 {{reference to local variable 'a' declared in 
enclosing function 'cwg712::f'}} FIXME

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


[clang] [clang][Sema] Re-use existing BinaryOperator if possible (PR #90625)

2024-04-30 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

`clang-format` issues an error for the comments from a previous commit wrote by 
a different author.
I'd like to disregard the clang-format errror, so to keep the diff of this 
commit minimial.

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


[clang] [clang] Prevent dangling StringRefs (PR #98699)

2024-07-12 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 created 
https://github.com/llvm/llvm-project/pull/98699

Fix locations where dangling StringRefs are created.

* `ConstraintSatisfaction::SubstitutionDiagnostic`: typedef of 
`std::pair`

* `concepts::Requirement::SubstitutionDiagnostic`: struct whose 1st and 3rd 
data members are `StringRef`s

Fixes #98667

>From 68d85e0409ce6a3184f53918b99b3e77bfab Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Fri, 12 Jul 2024 17:40:59 -0500
Subject: [PATCH] [clang] Prevent dangling StringRefs

Fix locations where dangling StringRefs are created.

* `ConstraintSatisfaction::SubstitutionDiagnostic`:
   typedef of `std::pair`

* `concepts::Requirement::SubstitutionDiagnostic`:
   struct whose 1st and 3rd data members are `StringRef`s

Fixes #98667
---
 clang/lib/Serialization/ASTReaderStmt.cpp | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp 
b/clang/lib/Serialization/ASTReaderStmt.cpp
index 5a5d7be69a2c3..ecbc57d642ca7 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -797,10 +797,14 @@ readConstraintSatisfaction(ASTRecordReader &Record) {
   if (/* IsDiagnostic */Record.readInt()) {
 SourceLocation DiagLocation = Record.readSourceLocation();
 std::string DiagMessage = Record.readString();
+char *DBuf = new (Record.getContext()) char[DiagMessage.size()];
+std::copy(DiagMessage.begin(), DiagMessage.end(), DBuf);
+
 Satisfaction.Details.emplace_back(
-ConstraintExpr, new (Record.getContext())
-ConstraintSatisfaction::SubstitutionDiagnostic{
-DiagLocation, DiagMessage});
+ConstraintExpr,
+new (Record.getContext())
+ConstraintSatisfaction::SubstitutionDiagnostic{
+DiagLocation, StringRef(DBuf, DiagMessage.size())});
   } else
 Satisfaction.Details.emplace_back(ConstraintExpr, Record.readExpr());
 }
@@ -822,11 +826,18 @@ void ASTStmtReader::VisitConceptSpecializationExpr(
 static concepts::Requirement::SubstitutionDiagnostic *
 readSubstitutionDiagnostic(ASTRecordReader &Record) {
   std::string SubstitutedEntity = Record.readString();
+  char *SBuf = new (Record.getContext()) char[SubstitutedEntity.size()];
+  std::copy(SubstitutedEntity.begin(), SubstitutedEntity.end(), SBuf);
+
   SourceLocation DiagLoc = Record.readSourceLocation();
   std::string DiagMessage = Record.readString();
+  char *DBuf = new (Record.getContext()) char[DiagMessage.size()];
+  std::copy(DiagMessage.begin(), DiagMessage.end(), DBuf);
+
   return new (Record.getContext())
-  concepts::Requirement::SubstitutionDiagnostic{SubstitutedEntity, DiagLoc,
-DiagMessage};
+  concepts::Requirement::SubstitutionDiagnostic{
+  StringRef(SBuf, SubstitutedEntity.size()), DiagLoc,
+  StringRef(DBuf, DiagMessage.size())};
 }
 
 void ASTStmtReader::VisitRequiresExpr(RequiresExpr *E) {

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


[clang] [clang] Prevent dangling StringRefs (PR #98699)

2024-07-13 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 updated 
https://github.com/llvm/llvm-project/pull/98699

>From 07648c7efab15786c36dbcd265015d945b627725 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Fri, 12 Jul 2024 17:40:59 -0500
Subject: [PATCH 1/2] [clang] Prevent dangling StringRefs

Fix locations where dangling StringRefs are created.

* `ConstraintSatisfaction::SubstitutionDiagnostic`:
   typedef of `std::pair`

* `concepts::Requirement::SubstitutionDiagnostic`:
   struct whose 1st and 3rd data members are `StringRef`s

Fixes #98667
---
 clang/lib/Serialization/ASTReaderStmt.cpp | 16 +---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp 
b/clang/lib/Serialization/ASTReaderStmt.cpp
index 6ccb4b01a036a..da67a4fcab5cb 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -796,10 +796,13 @@ readConstraintSatisfaction(ASTRecordReader &Record) {
   if (/* IsDiagnostic */Record.readInt()) {
 SourceLocation DiagLocation = Record.readSourceLocation();
 std::string DiagMessage = Record.readString();
+char *DBuf = new (Record.getContext()) char[DiagMessage.size()];
+std::copy(DiagMessage.begin(), DiagMessage.end(), DBuf);
+
 Satisfaction.Details.emplace_back(
 new (Record.getContext())
 ConstraintSatisfaction::SubstitutionDiagnostic(DiagLocation,
-   DiagMessage));
+   StringRef(DBuf, 
DiagMessage.size(;
   } else
 Satisfaction.Details.emplace_back(Record.readExpr());
 }
@@ -821,11 +824,18 @@ void ASTStmtReader::VisitConceptSpecializationExpr(
 static concepts::Requirement::SubstitutionDiagnostic *
 readSubstitutionDiagnostic(ASTRecordReader &Record) {
   std::string SubstitutedEntity = Record.readString();
+  char *SBuf = new (Record.getContext()) char[SubstitutedEntity.size()];
+  std::copy(SubstitutedEntity.begin(), SubstitutedEntity.end(), SBuf);
+
   SourceLocation DiagLoc = Record.readSourceLocation();
   std::string DiagMessage = Record.readString();
+  char *DBuf = new (Record.getContext()) char[DiagMessage.size()];
+  std::copy(DiagMessage.begin(), DiagMessage.end(), DBuf);
+
   return new (Record.getContext())
-  concepts::Requirement::SubstitutionDiagnostic{SubstitutedEntity, DiagLoc,
-DiagMessage};
+  concepts::Requirement::SubstitutionDiagnostic{
+  StringRef(SBuf, SubstitutedEntity.size()), DiagLoc,
+  StringRef(DBuf, DiagMessage.size())};
 }
 
 void ASTStmtReader::VisitRequiresExpr(RequiresExpr *E) {

>From 3b4dc1fe464bb914ac76d460d96dc39f75afd79a Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Sat, 13 Jul 2024 10:04:37 -0500
Subject: [PATCH 2/2] Extract mem alloc & string copy logic to helper function

Add Clang release note item
---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/Serialization/ASTReaderStmt.cpp | 28 ---
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5dc0f8b7e0bbb..055b426860df2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -830,6 +830,8 @@ Bug Fixes in This Version
 - ``__is_trivially_equality_comparable`` no longer returns true for types which
   have a constrained defaulted comparison operator (#GH89293).
 
+- Fixed Clang from generating dangling StringRefs when deserializing Exprs & 
Stmts (#GH98667)
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp 
b/clang/lib/Serialization/ASTReaderStmt.cpp
index da67a4fcab5cb..b2b0a30457d23 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -785,6 +785,12 @@ void 
ASTStmtReader::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
   E->setRParenLoc(readSourceLocation());
 }
 
+static StringRef saveStrToCtx(const std::string &S, ASTContext &Ctx) {
+  char *Buf = new (Ctx) char[S.size()];
+  std::copy(S.begin(), S.end(), Buf);
+  return StringRef(Buf, S.size());
+}
+
 static ConstraintSatisfaction
 readConstraintSatisfaction(ASTRecordReader &Record) {
   ConstraintSatisfaction Satisfaction;
@@ -795,14 +801,13 @@ readConstraintSatisfaction(ASTRecordReader &Record) {
 for (unsigned i = 0; i != NumDetailRecords; ++i) {
   if (/* IsDiagnostic */Record.readInt()) {
 SourceLocation DiagLocation = Record.readSourceLocation();
-std::string DiagMessage = Record.readString();
-char *DBuf = new (Record.getContext()) char[DiagMessage.size()];
-std::copy(DiagMessage.begin(), DiagMessage.end(), DBuf);
+StringRef DiagMessage =
+saveStrToCtx(Record.readString(), Record.getContext());
 
 Satisfaction.Details.emplace_bac

[clang] [clang][Sema] Re-use existing BinaryOperator if possible (PR #90625)

2024-04-30 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 updated 
https://github.com/llvm/llvm-project/pull/90625

>From 3b2f810ff3798ef073a8d1a10ca6fbafdbdb4641 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Tue, 30 Apr 2024 11:18:15 -0500
Subject: [PATCH] [clang][Sema] Re-use existing BinaryOperator if possible

First round of Sema checks were run at initial parsing step. Creating a new
BinaryOperator instance (with the re-built LHS or RHS) will trigger another
round of Sema checks, which can lead to duplicate diagnostic warning messages.

All we want here is to replace the LHS or RHS with a NonOdrUse version. Don't
create a new BinaryOperator, but simply replace the LHS or RHS of the given
BinaryOperator.

Fixes #45783
---
 clang/lib/Sema/SemaExpr.cpp  | 7 +++
 clang/test/CXX/drs/dr7xx.cpp | 2 --
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 0c37f43f75401b..0cca02c338954a 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -19707,18 +19707,17 @@ static ExprResult 
rebuildPotentialResultsAsNonOdrUsed(Sema &S, Expr *E,
   ExprResult Sub = Rebuild(LHS);
   if (!Sub.isUsable())
 return Sub;
-  LHS = Sub.get();
+  BO->setLHS(Sub.get());
 //   -- If e is a comma expression, ...
 } else if (BO->getOpcode() == BO_Comma) {
   ExprResult Sub = Rebuild(RHS);
   if (!Sub.isUsable())
 return Sub;
-  RHS = Sub.get();
+  BO->setRHS(Sub.get());
 } else {
   break;
 }
-return S.BuildBinOp(nullptr, BO->getOperatorLoc(), BO->getOpcode(),
-LHS, RHS);
+return ExprResult(BO);
   }
 
   //   -- If e has the form (e1)...
diff --git a/clang/test/CXX/drs/dr7xx.cpp b/clang/test/CXX/drs/dr7xx.cpp
index 69ee6d6d4e6ae0..0300dae08d6d31 100644
--- a/clang/test/CXX/drs/dr7xx.cpp
+++ b/clang/test/CXX/drs/dr7xx.cpp
@@ -28,10 +28,8 @@ namespace cwg712 { // cwg712: partial
 use(a);
 use((a));
 use(cond ? a : a);
-// FIXME: should only warn once
 use((cond, a));
 // expected-warning@-1 {{left operand of comma operator has no effect}}
-// expected-warning@-2 {{left operand of comma operator has no effect}}
 
 (void)a;
 // expected-error@-1 {{reference to local variable 'a' declared in 
enclosing function 'cwg712::f'}} FIXME

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


[clang] [clang][Sema] Re-use existing BinaryOperator if possible (PR #90625)

2024-05-01 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

Buildkite passed on Linux x64 but failed on Windows x64 .
Test log doesn't show any test failures except for `XFAIL` runs, so I'm not 
sure what's causing the failure.

Will rebase onto latest `main` to try the build again.



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


[clang] [clang][Sema] Re-use existing BinaryOperator if possible (PR #90625)

2024-05-01 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 updated 
https://github.com/llvm/llvm-project/pull/90625

>From 0a1598d0e00cbbfd0320ea72491500957ddb6b52 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Tue, 30 Apr 2024 11:18:15 -0500
Subject: [PATCH] [clang][Sema] Re-use existing BinaryOperator if possible

First round of Sema checks were run at initial parsing step. Creating a new
BinaryOperator instance (with the re-built LHS or RHS) will trigger another
round of Sema checks, which can lead to duplicate diagnostic warning messages.

All we want here is to replace the LHS or RHS with a NonOdrUse version. Don't
create a new BinaryOperator, but simply replace the LHS or RHS of the given
BinaryOperator.

Fixes #45783
---
 clang/lib/Sema/SemaExpr.cpp  | 7 +++
 clang/test/CXX/drs/dr7xx.cpp | 2 --
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 0c37f43f75401b..0cca02c338954a 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -19707,18 +19707,17 @@ static ExprResult 
rebuildPotentialResultsAsNonOdrUsed(Sema &S, Expr *E,
   ExprResult Sub = Rebuild(LHS);
   if (!Sub.isUsable())
 return Sub;
-  LHS = Sub.get();
+  BO->setLHS(Sub.get());
 //   -- If e is a comma expression, ...
 } else if (BO->getOpcode() == BO_Comma) {
   ExprResult Sub = Rebuild(RHS);
   if (!Sub.isUsable())
 return Sub;
-  RHS = Sub.get();
+  BO->setRHS(Sub.get());
 } else {
   break;
 }
-return S.BuildBinOp(nullptr, BO->getOperatorLoc(), BO->getOpcode(),
-LHS, RHS);
+return ExprResult(BO);
   }
 
   //   -- If e has the form (e1)...
diff --git a/clang/test/CXX/drs/dr7xx.cpp b/clang/test/CXX/drs/dr7xx.cpp
index 69ee6d6d4e6ae0..0300dae08d6d31 100644
--- a/clang/test/CXX/drs/dr7xx.cpp
+++ b/clang/test/CXX/drs/dr7xx.cpp
@@ -28,10 +28,8 @@ namespace cwg712 { // cwg712: partial
 use(a);
 use((a));
 use(cond ? a : a);
-// FIXME: should only warn once
 use((cond, a));
 // expected-warning@-1 {{left operand of comma operator has no effect}}
-// expected-warning@-2 {{left operand of comma operator has no effect}}
 
 (void)a;
 // expected-error@-1 {{reference to local variable 'a' declared in 
enclosing function 'cwg712::f'}} FIXME

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


[clang] [clang][Sema] Re-use existing BinaryOperator if possible (PR #90625)

2024-05-01 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 updated 
https://github.com/llvm/llvm-project/pull/90625

>From 0a1598d0e00cbbfd0320ea72491500957ddb6b52 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Tue, 30 Apr 2024 11:18:15 -0500
Subject: [PATCH 1/2] [clang][Sema] Re-use existing BinaryOperator if possible

First round of Sema checks were run at initial parsing step. Creating a new
BinaryOperator instance (with the re-built LHS or RHS) will trigger another
round of Sema checks, which can lead to duplicate diagnostic warning messages.

All we want here is to replace the LHS or RHS with a NonOdrUse version. Don't
create a new BinaryOperator, but simply replace the LHS or RHS of the given
BinaryOperator.

Fixes #45783
---
 clang/lib/Sema/SemaExpr.cpp  | 7 +++
 clang/test/CXX/drs/dr7xx.cpp | 2 --
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 0c37f43f75401b..0cca02c338954a 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -19707,18 +19707,17 @@ static ExprResult 
rebuildPotentialResultsAsNonOdrUsed(Sema &S, Expr *E,
   ExprResult Sub = Rebuild(LHS);
   if (!Sub.isUsable())
 return Sub;
-  LHS = Sub.get();
+  BO->setLHS(Sub.get());
 //   -- If e is a comma expression, ...
 } else if (BO->getOpcode() == BO_Comma) {
   ExprResult Sub = Rebuild(RHS);
   if (!Sub.isUsable())
 return Sub;
-  RHS = Sub.get();
+  BO->setRHS(Sub.get());
 } else {
   break;
 }
-return S.BuildBinOp(nullptr, BO->getOperatorLoc(), BO->getOpcode(),
-LHS, RHS);
+return ExprResult(BO);
   }
 
   //   -- If e has the form (e1)...
diff --git a/clang/test/CXX/drs/dr7xx.cpp b/clang/test/CXX/drs/dr7xx.cpp
index 69ee6d6d4e6ae0..0300dae08d6d31 100644
--- a/clang/test/CXX/drs/dr7xx.cpp
+++ b/clang/test/CXX/drs/dr7xx.cpp
@@ -28,10 +28,8 @@ namespace cwg712 { // cwg712: partial
 use(a);
 use((a));
 use(cond ? a : a);
-// FIXME: should only warn once
 use((cond, a));
 // expected-warning@-1 {{left operand of comma operator has no effect}}
-// expected-warning@-2 {{left operand of comma operator has no effect}}
 
 (void)a;
 // expected-error@-1 {{reference to local variable 'a' declared in 
enclosing function 'cwg712::f'}} FIXME

>From a7ea985860e0905b1904d58b188a66b94f236fb6 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Wed, 1 May 2024 14:32:10 -0500
Subject: [PATCH 2/2] Add release-note item

---
 clang/docs/ReleaseNotes.rst | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2c5308fbcb319a..ee2387245b6495 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -502,6 +502,9 @@ Bug Fixes in This Version
   The values of 0 and 1 block any unrolling of the loop. This keeps the same 
behavior with GCC.
   Fixes (`#88624 `_).
 
+- Clang will no longer emit a duplicate -Wunused-value warning for an 
expression
+  `(A, B)` which evaluates to glvalue `B` that can be converted to non 
ODR-use. (#GH45783)
+
 Bug Fixes to Compiler Builtins
 ^^
 

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


[clang] [clang][Sema] Re-use existing BinaryOperator if possible (PR #90625)

2024-05-02 Thread Youngsuk Kim via cfe-commits

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


[clang] 1efc191 - [clang][Driver] Iterate with const reference (NFC)

2024-05-03 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2024-05-03T05:18:27-05:00
New Revision: 1efc1918502bd8c9cf2431af38d754878eac071a

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

LOG: [clang][Driver] Iterate with const reference (NFC)

Closes #90282

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 2cb0c721354499..f9ca76a5ac8007 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8105,7 +8105,7 @@ static EHFlags parseClangCLEHFlags(const Driver &D, const 
ArgList &Args,
 
   std::vector EHArgs =
   Args.getAllArgValues(options::OPT__SLASH_EH);
-  for (auto EHVal : EHArgs) {
+  for (const auto &EHVal : EHArgs) {
 for (size_t I = 0, E = EHVal.size(); I != E; ++I) {
   switch (EHVal[I]) {
   case 'a':



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


[clang] 2933ef2 - [clang][HIPUtility] Iterate by const reference (NFC)

2024-05-03 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2024-05-03T05:45:17-05:00
New Revision: 2933ef2da9103122a52066a1c680046d1bdacaed

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

LOG: [clang][HIPUtility] Iterate by const reference (NFC)

Closes #90284

Added: 


Modified: 
clang/lib/Driver/ToolChains/HIPUtility.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/HIPUtility.cpp 
b/clang/lib/Driver/ToolChains/HIPUtility.cpp
index 08c647dfcb6f72..b1ff697b368b13 100644
--- a/clang/lib/Driver/ToolChains/HIPUtility.cpp
+++ b/clang/lib/Driver/ToolChains/HIPUtility.cpp
@@ -60,9 +60,9 @@ class HIPUndefinedFatBinSymbols {
 Verbose(C.getArgs().hasArg(options::OPT_v)) {
 populateSymbols();
 if (Verbose) {
-  for (auto Name : FatBinSymbols)
+  for (const auto &Name : FatBinSymbols)
 llvm::errs() << "Found undefined HIP fatbin symbol: " << Name << "\n";
-  for (auto Name : GPUBinHandleSymbols)
+  for (const auto &Name : GPUBinHandleSymbols)
 llvm::errs() << "Found undefined HIP gpubin handle symbol: " << Name
  << "\n";
 }



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


  1   2   >