[clang] [NFC][Clang] Fix potential dereferencing of nullptr (PR #86759)

2024-03-27 Thread via cfe-commits

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


[clang] [NFC][Clang] Fix potential dereferencing of nullptr (PR #86759)

2024-03-27 Thread via cfe-commits

smanna12 wrote:

Thank you @tahonermann for reviews!

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


[clang] [NFC][Clang] Fix potential dereferencing of nullptr (PR #86759)

2024-03-27 Thread Tom Honermann via cfe-commits


@@ -289,7 +289,7 @@ class ComplexExprEmitter
 const BinOpInfo &Op);
 
   QualType GetHigherPrecisionFPType(QualType ElementType) {
-const auto *CurrentBT = dyn_cast(ElementType);
+const auto *CurrentBT = cast(ElementType);

tahonermann wrote:

This looks fine and is consistent with other type assumptions elsewhere in the 
same source file.

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


[clang] [NFC][Clang] Fix potential dereferencing of nullptr (PR #86759)

2024-03-27 Thread Tom Honermann via cfe-commits


@@ -2974,7 +2974,7 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
 if (auto *FPrime = SemaRef.InstantiateFunctionDeclaration(
 F, TemplateArgListForBuildingFPrime, AliasTemplate->getLocation(),
 Sema::CodeSynthesisContext::BuildingDeductionGuides)) {
-  auto *GG = dyn_cast(FPrime);
+  auto *GG = cast(FPrime);

tahonermann wrote:

I think this looks fine too. It is not trivial to ensure, but seems reasonable.

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


[clang] [NFC][Clang] Fix potential dereferencing of nullptr (PR #86759)

2024-03-27 Thread Tom Honermann via cfe-commits

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


[clang] [NFC][Clang] Fix potential dereferencing of nullptr (PR #86759)

2024-03-27 Thread Tom Honermann via cfe-commits

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

Looks good, thanks @smanna12!

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


[clang] [NFC][Clang] Fix potential dereferencing of nullptr (PR #86759)

2024-03-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-powerpc

Author: None (smanna12)


Changes

This patch replaces dyn_cast<> with cast<> to resolve potential 
static analyzer bugs for

1. Dereferencing a pointer issue with nullptr GVar when calling addAttribute() 
in AIXTargetCodeGenInfo::setTargetAttributes(clang::Decl const *, 
llvm::GlobalValue *, clang::CodeGen::CodeGenModule &).

2. Dereferencing a pointer issue with nullptr GG when calling 
getCorrespondingConstructor() in 
DeclareImplicitDeductionGuidesForTypeAlias(clang::Sema &, 
clang::TypeAliasTemplateDecl *, clang::SourceLocation).

3. Dereferencing a pointer issue with nullptr CurrentBT when calling getKind() 
in ComplexExprEmitter::GetHigherPrecisionFPType(clang::QualType).

---
Full diff: https://github.com/llvm/llvm-project/pull/86759.diff


3 Files Affected:

- (modified) clang/lib/CodeGen/CGExprComplex.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/PPC.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+1-1) 


``diff
diff --git a/clang/lib/CodeGen/CGExprComplex.cpp 
b/clang/lib/CodeGen/CGExprComplex.cpp
index b873bc6737bb0a..c3774d0cb75edc 100644
--- a/clang/lib/CodeGen/CGExprComplex.cpp
+++ b/clang/lib/CodeGen/CGExprComplex.cpp
@@ -289,7 +289,7 @@ class ComplexExprEmitter
 const BinOpInfo &Op);
 
   QualType GetHigherPrecisionFPType(QualType ElementType) {
-const auto *CurrentBT = dyn_cast(ElementType);
+const auto *CurrentBT = cast(ElementType);
 switch (CurrentBT->getKind()) {
 case BuiltinType::Kind::Float16:
   return CGF.getContext().FloatTy;
diff --git a/clang/lib/CodeGen/Targets/PPC.cpp 
b/clang/lib/CodeGen/Targets/PPC.cpp
index 00b04723f17dd2..3eadb19bd2058f 100644
--- a/clang/lib/CodeGen/Targets/PPC.cpp
+++ b/clang/lib/CodeGen/Targets/PPC.cpp
@@ -274,7 +274,7 @@ void AIXTargetCodeGenInfo::setTargetAttributes(
   if (!isa(GV))
 return;
 
-  auto *GVar = dyn_cast(GV);
+  auto *GVar = cast(GV);
   auto GVId = GV->getName();
 
   // Is this a global variable specified by the user as toc-data?
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 005529a53270c3..aab72dbaf48c46 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2974,7 +2974,7 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
 if (auto *FPrime = SemaRef.InstantiateFunctionDeclaration(
 F, TemplateArgListForBuildingFPrime, AliasTemplate->getLocation(),
 Sema::CodeSynthesisContext::BuildingDeductionGuides)) {
-  auto *GG = dyn_cast(FPrime);
+  auto *GG = cast(FPrime);
   buildDeductionGuide(SemaRef, AliasTemplate, FPrimeTemplateParamList,
   GG->getCorrespondingConstructor(),
   GG->getExplicitSpecifier(), GG->getTypeSourceInfo(),

``




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


[clang] [NFC][Clang] Fix potential dereferencing of nullptr (PR #86759)

2024-03-26 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: None (smanna12)


Changes

This patch replaces dyn_cast<> with cast<> to resolve potential 
static analyzer bugs for

1. Dereferencing a pointer issue with nullptr GVar when calling addAttribute() 
in AIXTargetCodeGenInfo::setTargetAttributes(clang::Decl const *, 
llvm::GlobalValue *, clang::CodeGen::CodeGenModule &).

2. Dereferencing a pointer issue with nullptr GG when calling 
getCorrespondingConstructor() in 
DeclareImplicitDeductionGuidesForTypeAlias(clang::Sema &, 
clang::TypeAliasTemplateDecl *, clang::SourceLocation).

3. Dereferencing a pointer issue with nullptr CurrentBT when calling getKind() 
in ComplexExprEmitter::GetHigherPrecisionFPType(clang::QualType).

---
Full diff: https://github.com/llvm/llvm-project/pull/86759.diff


3 Files Affected:

- (modified) clang/lib/CodeGen/CGExprComplex.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/PPC.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+1-1) 


``diff
diff --git a/clang/lib/CodeGen/CGExprComplex.cpp 
b/clang/lib/CodeGen/CGExprComplex.cpp
index b873bc6737bb0a..c3774d0cb75edc 100644
--- a/clang/lib/CodeGen/CGExprComplex.cpp
+++ b/clang/lib/CodeGen/CGExprComplex.cpp
@@ -289,7 +289,7 @@ class ComplexExprEmitter
 const BinOpInfo &Op);
 
   QualType GetHigherPrecisionFPType(QualType ElementType) {
-const auto *CurrentBT = dyn_cast(ElementType);
+const auto *CurrentBT = cast(ElementType);
 switch (CurrentBT->getKind()) {
 case BuiltinType::Kind::Float16:
   return CGF.getContext().FloatTy;
diff --git a/clang/lib/CodeGen/Targets/PPC.cpp 
b/clang/lib/CodeGen/Targets/PPC.cpp
index 00b04723f17dd2..3eadb19bd2058f 100644
--- a/clang/lib/CodeGen/Targets/PPC.cpp
+++ b/clang/lib/CodeGen/Targets/PPC.cpp
@@ -274,7 +274,7 @@ void AIXTargetCodeGenInfo::setTargetAttributes(
   if (!isa(GV))
 return;
 
-  auto *GVar = dyn_cast(GV);
+  auto *GVar = cast(GV);
   auto GVId = GV->getName();
 
   // Is this a global variable specified by the user as toc-data?
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 005529a53270c3..aab72dbaf48c46 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2974,7 +2974,7 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
 if (auto *FPrime = SemaRef.InstantiateFunctionDeclaration(
 F, TemplateArgListForBuildingFPrime, AliasTemplate->getLocation(),
 Sema::CodeSynthesisContext::BuildingDeductionGuides)) {
-  auto *GG = dyn_cast(FPrime);
+  auto *GG = cast(FPrime);
   buildDeductionGuide(SemaRef, AliasTemplate, FPrimeTemplateParamList,
   GG->getCorrespondingConstructor(),
   GG->getExplicitSpecifier(), GG->getTypeSourceInfo(),

``




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


[clang] [NFC][Clang] Fix potential dereferencing of nullptr (PR #86759)

2024-03-26 Thread via cfe-commits

https://github.com/smanna12 created 
https://github.com/llvm/llvm-project/pull/86759

This patch replaces dyn_cast<> with cast<> to resolve potential static analyzer 
bugs for

1. Dereferencing a pointer issue with nullptr GVar when calling addAttribute() 
in AIXTargetCodeGenInfo::setTargetAttributes(clang::Decl const *, 
llvm::GlobalValue *, clang::CodeGen::CodeGenModule &).

2. Dereferencing a pointer issue with nullptr GG when calling 
getCorrespondingConstructor() in 
DeclareImplicitDeductionGuidesForTypeAlias(clang::Sema &, 
clang::TypeAliasTemplateDecl *, clang::SourceLocation).

3. Dereferencing a pointer issue with nullptr CurrentBT when calling getKind() 
in ComplexExprEmitter::GetHigherPrecisionFPType(clang::QualType).

>From 1b0d28a8abc322753108d1771f4928cac96584ee Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Tue, 26 Mar 2024 19:24:42 -0700
Subject: [PATCH] [NFC][Clang] Fix potential dereferencing of nullptr

This patch replaces dyn_cast<> with cast<> to resolve potential static
analyzer bugs for

1. Dereferencing a pointer issue with nullptr GVar when calling addAttribute()
   in AIXTargetCodeGenInfo::setTargetAttributes(clang::Decl const *, 
llvm::GlobalValue *, clang::CodeGen::CodeGenModule &).

2. Dereferencing a pointer issue with nullptr GG when calling 
getCorrespondingConstructor() in 
DeclareImplicitDeductionGuidesForTypeAlias(clang::Sema &, 
clang::TypeAliasTemplateDecl *, clang::SourceLocation).

3. Dereferencing a pointer issue with nullptr CurrentBT when calling
   getKind() in ComplexExprEmitter::GetHigherPrecisionFPType(clang::QualType).
---
 clang/lib/CodeGen/CGExprComplex.cpp | 2 +-
 clang/lib/CodeGen/Targets/PPC.cpp   | 2 +-
 clang/lib/Sema/SemaTemplate.cpp | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprComplex.cpp 
b/clang/lib/CodeGen/CGExprComplex.cpp
index b873bc6737bb0a..c3774d0cb75edc 100644
--- a/clang/lib/CodeGen/CGExprComplex.cpp
+++ b/clang/lib/CodeGen/CGExprComplex.cpp
@@ -289,7 +289,7 @@ class ComplexExprEmitter
 const BinOpInfo &Op);
 
   QualType GetHigherPrecisionFPType(QualType ElementType) {
-const auto *CurrentBT = dyn_cast(ElementType);
+const auto *CurrentBT = cast(ElementType);
 switch (CurrentBT->getKind()) {
 case BuiltinType::Kind::Float16:
   return CGF.getContext().FloatTy;
diff --git a/clang/lib/CodeGen/Targets/PPC.cpp 
b/clang/lib/CodeGen/Targets/PPC.cpp
index 00b04723f17dd2..3eadb19bd2058f 100644
--- a/clang/lib/CodeGen/Targets/PPC.cpp
+++ b/clang/lib/CodeGen/Targets/PPC.cpp
@@ -274,7 +274,7 @@ void AIXTargetCodeGenInfo::setTargetAttributes(
   if (!isa(GV))
 return;
 
-  auto *GVar = dyn_cast(GV);
+  auto *GVar = cast(GV);
   auto GVId = GV->getName();
 
   // Is this a global variable specified by the user as toc-data?
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 005529a53270c3..aab72dbaf48c46 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2974,7 +2974,7 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
 if (auto *FPrime = SemaRef.InstantiateFunctionDeclaration(
 F, TemplateArgListForBuildingFPrime, AliasTemplate->getLocation(),
 Sema::CodeSynthesisContext::BuildingDeductionGuides)) {
-  auto *GG = dyn_cast(FPrime);
+  auto *GG = cast(FPrime);
   buildDeductionGuide(SemaRef, AliasTemplate, FPrimeTemplateParamList,
   GG->getCorrespondingConstructor(),
   GG->getExplicitSpecifier(), GG->getTypeSourceInfo(),

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