[clang] [Clang][Sema] Fix crash when type used in return statement contains errors (PR #79788)

2024-01-29 Thread Shafik Yaghmour via cfe-commits

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


[clang] [Clang][Sema] Fix crash when type used in return statement contains errors (PR #79788)

2024-01-29 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik updated 
https://github.com/llvm/llvm-project/pull/79788

>From f7f1007954503d013294c2e21ce2160dc7866164 Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour 
Date: Sun, 28 Jan 2024 22:42:53 -0800
Subject: [PATCH] [Clang][Sema] Fix crash when type used in return statement
 contains errors

In Sema in `BuildReturnStmt(...)` when we try to determine is the type is move
eligable or copy elidable we don't currently check of the init of the `VarDecl`
contain errors or not. This can lead to a crash since we may send a type that
is not complete into `getTypeInfo(...)` which does not allow this.

This fixes: https://github.com/llvm/llvm-project/issues/63244
https://github.com/llvm/llvm-project/issues/79745
---
 clang/docs/ReleaseNotes.rst  | 3 +++
 clang/lib/Sema/SemaStmt.cpp  | 2 ++
 clang/test/SemaCXX/deduced-return-type-cxx14.cpp | 9 +
 3 files changed, 14 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9d68be469dac394..078372731736e06 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -138,6 +138,9 @@ Bug Fixes to C++ Support
 - Fixed deducing auto& from const int in template parameters of partial
   specializations.
   (`#77189 `_)
+- Fix for crash when using a erroneous type in a return statement.
+  Fixes (`#63244 `_)
+  and (`#79745 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 9e7c8c7e4e8c12c..5d5a29b825ae7d7 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3391,6 +3391,8 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(Expr *,
   const auto *VD = dyn_cast(DR->getDecl());
   if (!VD)
 return NamedReturnInfo();
+  if (VD->getInit() && VD->getInit()->containsErrors())
+return NamedReturnInfo();
   NamedReturnInfo Res = getNamedReturnInfo(VD);
   if (Res.Candidate && !E->isXValue() &&
   (Mode == SimplerImplicitMoveMode::ForceOn ||
diff --git a/clang/test/SemaCXX/deduced-return-type-cxx14.cpp 
b/clang/test/SemaCXX/deduced-return-type-cxx14.cpp
index c0d43911b8c7174..415bbbf1a0bc509 100644
--- a/clang/test/SemaCXX/deduced-return-type-cxx14.cpp
+++ b/clang/test/SemaCXX/deduced-return-type-cxx14.cpp
@@ -724,3 +724,12 @@ struct DeducedTargetTypeOfConversionFunction {
   // since-cxx20-error@-1 {{'decltype(auto)' not allowed in declaration of 
conversion function template}}
 #endif
 };
+
+namespace GH79745 {
+template  struct a; // expected-note {{template is declared 
here}}
+auto f() {
+  a c; // cxx20_23-error {{implicit instantiation of undefined template}} \
+   // cxx14-error {{use of class template 'a' requires template arguments}}
+  return c;
+}
+}

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


[clang] [Clang][Sema] Fix crash when type used in return statement contains errors (PR #79788)

2024-01-29 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik updated 
https://github.com/llvm/llvm-project/pull/79788

>From dde16b48d563b3e279872081bad148614e9d28a3 Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour 
Date: Sun, 28 Jan 2024 22:42:53 -0800
Subject: [PATCH] [Clang][Sema] Fix crash when type used in return statement
 contains errors

In Sema in `BuildReturnStmt(...)` when we try to determine is the type is move
eligable or copy elidable we don't currently check of the init of the `VarDecl`
contain errors or not. This can lead to a crash since we may send a type that
is not complete into `getTypeInfo(...)` which does not allow this.

This fixes: https://github.com/llvm/llvm-project/issues/63244
https://github.com/llvm/llvm-project/issues/79745
---
 clang/docs/ReleaseNotes.rst  | 3 +++
 clang/lib/Sema/SemaStmt.cpp  | 2 ++
 clang/test/SemaCXX/deduced-return-type-cxx14.cpp | 9 +
 3 files changed, 14 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9d68be469dac394..078372731736e06 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -138,6 +138,9 @@ Bug Fixes to C++ Support
 - Fixed deducing auto& from const int in template parameters of partial
   specializations.
   (`#77189 `_)
+- Fix for crash when using a erroneous type in a return statement.
+  Fixes (`#63244 `_)
+  and (`#79745 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 9e7c8c7e4e8c12c..5d5a29b825ae7d7 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3391,6 +3391,8 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(Expr *,
   const auto *VD = dyn_cast(DR->getDecl());
   if (!VD)
 return NamedReturnInfo();
+  if (VD->getInit() && VD->getInit()->containsErrors())
+return NamedReturnInfo();
   NamedReturnInfo Res = getNamedReturnInfo(VD);
   if (Res.Candidate && !E->isXValue() &&
   (Mode == SimplerImplicitMoveMode::ForceOn ||
diff --git a/clang/test/SemaCXX/deduced-return-type-cxx14.cpp 
b/clang/test/SemaCXX/deduced-return-type-cxx14.cpp
index c0d43911b8c7174..415bbbf1a0bc509 100644
--- a/clang/test/SemaCXX/deduced-return-type-cxx14.cpp
+++ b/clang/test/SemaCXX/deduced-return-type-cxx14.cpp
@@ -724,3 +724,12 @@ struct DeducedTargetTypeOfConversionFunction {
   // since-cxx20-error@-1 {{'decltype(auto)' not allowed in declaration of 
conversion function template}}
 #endif
 };
+
+namespace GH79745 {
+template  struct a; // expected-note {{template is declared 
here}}
+auto f() {
+  a c; // cxx20_23-error {{implicit instantiation of undefined template}} \
+   // cxx14-error {{use of class template 'a' requires template arguments}}
+  return c;
+}
+}

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


[clang] [Clang][Sema] Fix crash when type used in return statement contains errors (PR #79788)

2024-01-29 Thread Shafik Yaghmour via cfe-commits

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


[clang] [Clang][Sema] Fix crash when type used in return statement contains errors (PR #79788)

2024-01-29 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

NIT: `eligable ` -> `eligible` in the description.

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


[clang] [Clang][Sema] Fix crash when type used in return statement contains errors (PR #79788)

2024-01-29 Thread via cfe-commits

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

Missing changelog, otherwise LGTM

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


[clang] [Clang][Sema] Fix crash when type used in return statement contains errors (PR #79788)

2024-01-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Shafik Yaghmour (shafik)


Changes

In Sema in `BuildReturnStmt(...)` when we try to determine is the type is move 
eligable or copy elidable we don't currently check of the init of the `VarDecl` 
contain errors or not. This can lead to a crash since we may send a type that 
is not complete into `getTypeInfo(...)` which does not allow this.

This fixes: https://github.com/llvm/llvm-project/issues/63244
https://github.com/llvm/llvm-project/issues/79745

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaStmt.cpp (+2) 
- (modified) clang/test/SemaCXX/deduced-return-type-cxx14.cpp (+9) 


``diff
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 9e7c8c7e4e8c12..5d5a29b825ae7d 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3391,6 +3391,8 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(Expr *,
   const auto *VD = dyn_cast(DR->getDecl());
   if (!VD)
 return NamedReturnInfo();
+  if (VD->getInit() && VD->getInit()->containsErrors())
+return NamedReturnInfo();
   NamedReturnInfo Res = getNamedReturnInfo(VD);
   if (Res.Candidate && !E->isXValue() &&
   (Mode == SimplerImplicitMoveMode::ForceOn ||
diff --git a/clang/test/SemaCXX/deduced-return-type-cxx14.cpp 
b/clang/test/SemaCXX/deduced-return-type-cxx14.cpp
index c0d43911b8c717..415bbbf1a0bc50 100644
--- a/clang/test/SemaCXX/deduced-return-type-cxx14.cpp
+++ b/clang/test/SemaCXX/deduced-return-type-cxx14.cpp
@@ -724,3 +724,12 @@ struct DeducedTargetTypeOfConversionFunction {
   // since-cxx20-error@-1 {{'decltype(auto)' not allowed in declaration of 
conversion function template}}
 #endif
 };
+
+namespace GH79745 {
+template  struct a; // expected-note {{template is declared 
here}}
+auto f() {
+  a c; // cxx20_23-error {{implicit instantiation of undefined template}} \
+   // cxx14-error {{use of class template 'a' requires template arguments}}
+  return c;
+}
+}

``




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


[clang] [Clang][Sema] Fix crash when type used in return statement contains errors (PR #79788)

2024-01-28 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik created 
https://github.com/llvm/llvm-project/pull/79788

In Sema in `BuildReturnStmt(...)` when we try to determine is the type is move 
eligable or copy elidable we don't currently check of the init of the `VarDecl` 
contain errors or not. This can lead to a crash since we may send a type that 
is not complete into `getTypeInfo(...)` which does not allow this.

This fixes: https://github.com/llvm/llvm-project/issues/63244
https://github.com/llvm/llvm-project/issues/79745

>From 82d2561488a13edd9527737fbcc2391bb30a78e8 Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour 
Date: Sun, 28 Jan 2024 22:42:53 -0800
Subject: [PATCH] [Clang][Sema] Fix crash when type used in return statement
 contains errors

In Sema in `BuildReturnStmt(...)` when we try to determine is the type is move
eligable or copy elidable we don't currently check of the init of the `VarDecl`
contain errors or not. This can lead to a crash since we may send a type that
is not complete into `getTypeInfo(...)` which does not allow this.

This fixes: https://github.com/llvm/llvm-project/issues/63244
https://github.com/llvm/llvm-project/issues/79745
---
 clang/lib/Sema/SemaStmt.cpp  | 2 ++
 clang/test/SemaCXX/deduced-return-type-cxx14.cpp | 9 +
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 9e7c8c7e4e8c12c..5d5a29b825ae7d7 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3391,6 +3391,8 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(Expr *,
   const auto *VD = dyn_cast(DR->getDecl());
   if (!VD)
 return NamedReturnInfo();
+  if (VD->getInit() && VD->getInit()->containsErrors())
+return NamedReturnInfo();
   NamedReturnInfo Res = getNamedReturnInfo(VD);
   if (Res.Candidate && !E->isXValue() &&
   (Mode == SimplerImplicitMoveMode::ForceOn ||
diff --git a/clang/test/SemaCXX/deduced-return-type-cxx14.cpp 
b/clang/test/SemaCXX/deduced-return-type-cxx14.cpp
index c0d43911b8c7174..415bbbf1a0bc509 100644
--- a/clang/test/SemaCXX/deduced-return-type-cxx14.cpp
+++ b/clang/test/SemaCXX/deduced-return-type-cxx14.cpp
@@ -724,3 +724,12 @@ struct DeducedTargetTypeOfConversionFunction {
   // since-cxx20-error@-1 {{'decltype(auto)' not allowed in declaration of 
conversion function template}}
 #endif
 };
+
+namespace GH79745 {
+template  struct a; // expected-note {{template is declared 
here}}
+auto f() {
+  a c; // cxx20_23-error {{implicit instantiation of undefined template}} \
+   // cxx14-error {{use of class template 'a' requires template arguments}}
+  return c;
+}
+}

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