r284673 - Fix crash on noreturn conversion in unprototyped function type. Thanks to Keith
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 19 17:01:37 PDT 2016
Author: rsmith
Date: Wed Oct 19 19:01:36 2016
New Revision: 284673
URL: http://llvm.org/viewvc/llvm-project?rev=284673&view=rev
Log:
Fix crash on noreturn conversion in unprototyped function type. Thanks to Keith
Walker for spotting the bug.
Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/Sema/initialize-noreturn.c
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=284673&r1=284672&r2=284673&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Oct 19 19:01:36 2016
@@ -1432,7 +1432,7 @@ bool Sema::IsFunctionConversion(QualType
const auto *FromFn = cast<FunctionType>(CanFrom);
FunctionType::ExtInfo FromEInfo = FromFn->getExtInfo();
- const auto *ToFn = dyn_cast<FunctionProtoType>(CanTo);
+ const auto *ToFn = cast<FunctionType>(CanTo);
FunctionType::ExtInfo ToEInfo = ToFn->getExtInfo();
bool Changed = false;
@@ -1445,7 +1445,7 @@ bool Sema::IsFunctionConversion(QualType
// Drop 'noexcept' if not present in target type.
if (const auto *FromFPT = dyn_cast<FunctionProtoType>(FromFn)) {
- const auto *ToFPT = dyn_cast<FunctionProtoType>(ToFn);
+ const auto *ToFPT = cast<FunctionProtoType>(ToFn);
if (FromFPT->isNothrow(Context) && !ToFPT->isNothrow(Context)) {
FromFn = cast<FunctionType>(
Context.getFunctionType(FromFPT->getReturnType(),
Modified: cfe/trunk/test/Sema/initialize-noreturn.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/initialize-noreturn.c?rev=284673&r1=284672&r2=284673&view=diff
==============================================================================
--- cfe/trunk/test/Sema/initialize-noreturn.c (original)
+++ cfe/trunk/test/Sema/initialize-noreturn.c Wed Oct 19 19:01:36 2016
@@ -4,13 +4,24 @@
typedef void (*Fn_noret)(void) __attribute__((noreturn));
typedef void (*Fn_ret)(void);
+typedef void (*Fn_noret_noproto)() __attribute__((noreturn));
+typedef void (*Fn_ret_noproto)();
+
void foo(void);
void foo_noret(void) __attribute__((noreturn));
+void foo_noproto();
+void foo_noret_noproto() __attribute__((noreturn));
+
void test() {
Fn_noret fn2 = &foo; // expected-warning {{incompatible function pointer types initializing 'Fn_noret'}}
Fn_noret fn3 = &foo_noret;
Fn_ret fn4 = &foo_noret;
Fn_ret fn5 = &foo;
+
+ Fn_noret_noproto fn6 = &foo_noproto; // expected-warning {{incompatible function pointer types initializing 'Fn_noret_noproto'}}
+ Fn_noret_noproto fn7 = &foo_noret_noproto;
+ Fn_ret_noproto fn8 = &foo_noret_noproto;
+ Fn_ret_noproto fn9 = &foo_noproto;
}
More information about the cfe-commits
mailing list