[clang] [CodeGen] Fix new-delete-type-mismatch in ~CodeGenTypes() (PR #135787)

2025-04-15 Thread Antonio Maiorano via cfe-commits

amaiorano wrote:

> Please also make the unused "operator delete" in CGFunctionInfo.h deleted, 
> since it shouldn't have any callers.
> 
> I think this never actually led to a real issue because of that operator 
> delete... it calls the right deallocation function even if it's technically 
> undefined. So the only way to spot an issue would be a sanitizer that 
> specifically checks for this. But I'm happy to "fix" this anyway.

Just to clarify, this was caught in an ASAN build of DXC, which is a fork of 
Clang. This may be reproducible with Clang by compiling with 
`-fsized-deallocation`.

https://github.com/llvm/llvm-project/pull/135787
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CodeGen] Fix new-delete-type-mismatch in ~CodeGenTypes() (PR #135787)

2025-04-15 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

Please also make the unused "operator delete" in CGFunctionInfo.h deleted, 
since it shouldn't have any callers.

I think this never actually led to a real issue because of that operator 
delete... it calls the right deallocation function even if it's technically 
undefined.  So the only way to spot an issue would be a sanitizer that 
specifically checks for this.  But I'm happy to "fix" this anyway.

https://github.com/llvm/llvm-project/pull/135787
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CodeGen] Fix new-delete-type-mismatch in ~CodeGenTypes() (PR #135787)

2025-04-15 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp -- 
clang/lib/CodeGen/CodeGenTypes.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp 
b/clang/lib/CodeGen/CodeGenTypes.cpp
index 3600203fe..80997580b 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -39,8 +39,9 @@ CodeGenTypes::CodeGenTypes(CodeGenModule &cgm)
 }
 
 CodeGenTypes::~CodeGenTypes() {
-  for (llvm::FoldingSet::iterator
-   I = FunctionInfos.begin(), E = FunctionInfos.end(); I != E; ) {
+  for (llvm::FoldingSet::iterator I = FunctionInfos.begin(),
+  E = FunctionInfos.end();
+   I != E;) {
 I->~CGFunctionInfo();
 operator delete(&*I++);
   }

``




https://github.com/llvm/llvm-project/pull/135787
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CodeGen] Fix new-delete-type-mismatch in ~CodeGenTypes() (PR #135787)

2025-04-15 Thread via cfe-commits

https://github.com/m1kit updated 
https://github.com/llvm/llvm-project/pull/135787

>From 15631133faed63a1c4bf7b3c9076629985e48bf9 Mon Sep 17 00:00:00 2001
From: mikit <[email protected]>
Date: Tue, 15 Apr 2025 22:32:24 +0900
Subject: [PATCH 1/2] [CodeGen] Fix new-delete-type-mismatch in ~CodeGenTypes()

It is undefined behavior to use `delete` expression on something
which was not created with corresponding `new` expression.
Switching to explicit global `operator delete()` call to match with
`operator new()` call at `CGFunctionInfo::create()`.

This issue is raised by Chromium ClusterFuzz, with ASan enabled.
https://crbug.com/410141973
---
 clang/lib/CodeGen/CodeGenTypes.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp 
b/clang/lib/CodeGen/CodeGenTypes.cpp
index b94c11802a268..dec3b087b107f 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -41,7 +41,7 @@ CodeGenTypes::CodeGenTypes(CodeGenModule &cgm)
 CodeGenTypes::~CodeGenTypes() {
   for (llvm::FoldingSet::iterator
I = FunctionInfos.begin(), E = FunctionInfos.end(); I != E; )
-delete &*I++;
+operator delete(&*I++);
 }
 
 CGCXXABI &CodeGenTypes::getCXXABI() const { return getCGM().getCXXABI(); }

>From 7fae0f5c2150cf443b37660f5429da3d5b388429 Mon Sep 17 00:00:00 2001
From: mikit <[email protected]>
Date: Tue, 15 Apr 2025 17:49:05 +
Subject: [PATCH 2/2] Call dtor

---
 clang/lib/CodeGen/CodeGenTypes.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp 
b/clang/lib/CodeGen/CodeGenTypes.cpp
index dec3b087b107f..3600203fe2fea 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -40,8 +40,10 @@ CodeGenTypes::CodeGenTypes(CodeGenModule &cgm)
 
 CodeGenTypes::~CodeGenTypes() {
   for (llvm::FoldingSet::iterator
-   I = FunctionInfos.begin(), E = FunctionInfos.end(); I != E; )
+   I = FunctionInfos.begin(), E = FunctionInfos.end(); I != E; ) {
+I->~CGFunctionInfo();
 operator delete(&*I++);
+  }
 }
 
 CGCXXABI &CodeGenTypes::getCXXABI() const { return getCGM().getCXXABI(); }

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CodeGen] Fix new-delete-type-mismatch in ~CodeGenTypes() (PR #135787)

2025-04-15 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

Do you need to invoke the destructor?

https://github.com/llvm/llvm-project/pull/135787
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CodeGen] Fix new-delete-type-mismatch in ~CodeGenTypes() (PR #135787)

2025-04-15 Thread via cfe-commits

github-actions[bot] wrote:

⚠️ We detected that you are using a GitHub private e-mail address to contribute 
to the repo. Please turn off [Keep my email addresses 
private](https://github.com/settings/emails) setting in your account. See 
[LLVM 
Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it)
 for more information.

https://github.com/llvm/llvm-project/pull/135787
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CodeGen] Fix new-delete-type-mismatch in ~CodeGenTypes() (PR #135787)

2025-04-15 Thread via cfe-commits

https://github.com/m1kit created 
https://github.com/llvm/llvm-project/pull/135787

It is undefined behavior to use `delete` expression on something which was not 
created with corresponding `new` expression. Switching to explicit global 
`operator delete()` call to match with `operator new()` call at 
`CGFunctionInfo::create()`.

This issue is raised by Chromium ClusterFuzz, with ASan enabled. 
https://crbug.com/410141973

>From 15631133faed63a1c4bf7b3c9076629985e48bf9 Mon Sep 17 00:00:00 2001
From: mikit <[email protected]>
Date: Tue, 15 Apr 2025 22:32:24 +0900
Subject: [PATCH] [CodeGen] Fix new-delete-type-mismatch in ~CodeGenTypes()

It is undefined behavior to use `delete` expression on something
which was not created with corresponding `new` expression.
Switching to explicit global `operator delete()` call to match with
`operator new()` call at `CGFunctionInfo::create()`.

This issue is raised by Chromium ClusterFuzz, with ASan enabled.
https://crbug.com/410141973
---
 clang/lib/CodeGen/CodeGenTypes.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp 
b/clang/lib/CodeGen/CodeGenTypes.cpp
index b94c11802a268..dec3b087b107f 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -41,7 +41,7 @@ CodeGenTypes::CodeGenTypes(CodeGenModule &cgm)
 CodeGenTypes::~CodeGenTypes() {
   for (llvm::FoldingSet::iterator
I = FunctionInfos.begin(), E = FunctionInfos.end(); I != E; )
-delete &*I++;
+operator delete(&*I++);
 }
 
 CGCXXABI &CodeGenTypes::getCXXABI() const { return getCGM().getCXXABI(); }

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CodeGen] Fix new-delete-type-mismatch in ~CodeGenTypes() (PR #135787)

2025-04-15 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment “Ping”. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

https://github.com/llvm/llvm-project/pull/135787
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CodeGen] Fix new-delete-type-mismatch in ~CodeGenTypes() (PR #135787)

2025-04-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: mikit (m1kit)


Changes

It is undefined behavior to use `delete` expression on something which was not 
created with corresponding `new` expression. Switching to explicit global 
`operator delete()` call to match with `operator new()` call at 
`CGFunctionInfo::create()`.

This issue is raised by Chromium ClusterFuzz, with ASan enabled. 
https://crbug.com/410141973

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+1-1) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp 
b/clang/lib/CodeGen/CodeGenTypes.cpp
index b94c11802a268..dec3b087b107f 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -41,7 +41,7 @@ CodeGenTypes::CodeGenTypes(CodeGenModule &cgm)
 CodeGenTypes::~CodeGenTypes() {
   for (llvm::FoldingSet::iterator
I = FunctionInfos.begin(), E = FunctionInfos.end(); I != E; )
-delete &*I++;
+operator delete(&*I++);
 }
 
 CGCXXABI &CodeGenTypes::getCXXABI() const { return getCGM().getCXXABI(); }

``




https://github.com/llvm/llvm-project/pull/135787
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CodeGen] Fix new-delete-type-mismatch in ~CodeGenTypes() (PR #135787)

2025-04-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: mikit (m1kit)


Changes

It is undefined behavior to use `delete` expression on something which was not 
created with corresponding `new` expression. Switching to explicit global 
`operator delete()` call to match with `operator new()` call at 
`CGFunctionInfo::create()`.

This issue is raised by Chromium ClusterFuzz, with ASan enabled. 
https://crbug.com/410141973

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+1-1) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp 
b/clang/lib/CodeGen/CodeGenTypes.cpp
index b94c11802a268..dec3b087b107f 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -41,7 +41,7 @@ CodeGenTypes::CodeGenTypes(CodeGenModule &cgm)
 CodeGenTypes::~CodeGenTypes() {
   for (llvm::FoldingSet::iterator
I = FunctionInfos.begin(), E = FunctionInfos.end(); I != E; )
-delete &*I++;
+operator delete(&*I++);
 }
 
 CGCXXABI &CodeGenTypes::getCXXABI() const { return getCGM().getCXXABI(); }

``




https://github.com/llvm/llvm-project/pull/135787
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits