Page MenuHomePhabricator

[Sema][C++] Propagate conversion type in order to specialize the diagnostics
ClosedPublic

Authored by Anastasia on Feb 6 2020, 3:34 AM.

Details

Summary

Currently in C++ we don't set/propagate what type of implicit conversions occurs on assignments/initializations/params/etc. Therefore the diagnostic provided is more generic than in C mode. This patch attempt to propagate the conversion kind through layers of C++ semantic checks. It is currently only used for address spaces conversion of nested pointers (from https://reviews.llvm.org/D73360). Setting this for other conversions would be quite a lot of work and I am not sure I feel confident to get it right. We could potentially gradually modify it as we go along. Although this is not an actively modified code base at the moment so not sure whether it will happen and when.

Feedback welcome!

Diff Detail

Event Timeline

Anastasia created this revision.Feb 6 2020, 3:34 AM
Anastasia edited the summary of this revision. (Show Details)Feb 6 2020, 3:35 AM

Hmm. The alternative approach, I suppose, would be to recognize that we're about to emit a generic error and just recheck assignment constraints to recompute the AssignConvertType.

Hmm. The alternative approach, I suppose, would be to recognize that we're about to emit a generic error and just recheck assignment constraints to recompute the AssignConvertType.

Indeed. It will need less changes around the code base but also means checks will be repeated.

This shouldn't be an expensive function call, and being a little inefficient on the error path to get better diagnostics is a good trade-off.

Anastasia updated this revision to Diff 244135.Feb 12 2020, 4:46 AM

If I reuse the helper checkPointerTypesForAssignment I end up with lots of error turned into warnings, see example in
test/SemaCXX/addr-of-overloaded-function.cpp

I guess we don't want them to be warnings? Should we duplicate all those as errors in C++?

It seems there are about 3 of them that would have to be duplicated:

[40/41] Running the Clang regression tests
llvm-lit: ...llvm/utils/lit/lit/llvm/config.py:342: note: using clang: ...build/bin/clang
FAIL: Clang :: CXX/conv/conv.fctptr/p1.cpp (1051 of 16808)
******************** TEST 'Clang :: CXX/conv/conv.fctptr/p1.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';   ...build/bin/clang -cc1 -internal-isystem ...build/lib/clang/11.0.0/include -nostdsysteminc -std=c++1z -verify ...clang/test/CXX/conv/conv.fctptr/p1.cpp -triple x86_64-unknown-unknown
--
Exit Code: 1

Command Output (stderr):
--
error: 'error' diagnostics expected but not seen: 
  File ...clang/test/CXX/conv/conv.fctptr/p1.cpp Line 14: assigning to 'Nothrow *' (aka 'void (*)() noexcept') from incompatible type 'Throw *' (aka 'void (*)()'): different exception specifications
error: 'warning' diagnostics seen but not expected: 
  File ...clang/test/CXX/conv/conv.fctptr/p1.cpp Line 14: incompatible function pointer types assigning to 'Nothrow *' (aka 'void (*)() noexcept') from 'Throw *' (aka 'void (*)()')
2 errors generated.

--

********************
FAIL: Clang :: CXX/except/except.handle/p16.cpp (1234 of 16808)
******************** TEST 'Clang :: CXX/except/except.handle/p16.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';   ...build/bin/clang -cc1 -internal-isystem ...build/lib/clang/11.0.0/include -nostdsysteminc -fcxx-exceptions -fexceptions -fsyntax-only -verify ...clang/test/CXX/except/except.handle/p16.cpp
--
Exit Code: 1

Command Output (stderr):
--
error: 'error' diagnostics expected but not seen: 
  File ...clang/test/CXX/except/except.handle/p16.cpp Line 14: assigning to 'float *' from incompatible type 'int *'
  File ...clang/test/CXX/except/except.handle/p16.cpp Line 19: assigning to 'int *' from incompatible type 'float *'
error: 'warning' diagnostics seen but not expected: 
  File ...clang/test/CXX/except/except.handle/p16.cpp Line 14: incompatible pointer types assigning to 'float *' from 'int *'
  File ...clang/test/CXX/except/except.handle/p16.cpp Line 19: incompatible pointer types assigning to 'int *' from 'float *'
4 errors generated.

--

********************
FAIL: Clang :: CXX/expr/p13.cpp (1350 of 16808)
******************** TEST 'Clang :: CXX/expr/p13.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';   ...build/bin/clang -cc1 -internal-isystem ...build/lib/clang/11.0.0/include -nostdsysteminc -std=c++1z -verify ...clang/test/CXX/expr/p13.cpp -fexceptions -fcxx-exceptions -Wno-dynamic-exception-spec
--
Exit Code: 1

Command Output (stderr):
--
error: 'error' diagnostics expected but not seen: 
  File ...clang/test/CXX/expr/p13.cpp Line 14: different exception specifications
error: 'warning' diagnostics seen but not expected: 
  File ...clang/test/CXX/expr/p13.cpp Line 14: incompatible function pointer types assigning to 'A' (aka 'void (*)() noexcept') from 'void (*)()'
2 errors generated.

--

********************
FAIL: Clang :: CXX/temp/temp.decls/temp.class/temp.mem.class/p1.cpp (1519 of 16808)
******************** TEST 'Clang :: CXX/temp/temp.decls/temp.class/temp.mem.class/p1.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';   ...build/bin/clang -cc1 -internal-isystem ...build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -verify ...clang/test/CXX/temp/temp.decls/temp.class/temp.mem.class/p1.cpp
--
Exit Code: 1

Command Output (stderr):
--
error: 'error' diagnostics expected but not seen: 
  File ...clang/test/CXX/temp/temp.decls/temp.class/temp.mem.class/p1.cpp Line 13: incompatible
error: 'warning' diagnostics seen but not expected: 
  File ...clang/test/CXX/temp/temp.decls/temp.class/temp.mem.class/p1.cpp Line 13: incompatible pointer types assigning to 'int *' from 'float *'
2 errors generated.

--

********************
FAIL: Clang :: SemaCXX/addr-of-overloaded-function.cpp (9959 of 16808)
******************** TEST 'Clang :: SemaCXX/addr-of-overloaded-function.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';   ...build/bin/clang -cc1 -internal-isystem ...build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -verify ...clang/test/SemaCXX/addr-of-overloaded-function.cpp
: 'RUN: at line 2';   ...build/bin/clang -cc1 -internal-isystem ...build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -verify -std=c++98 ...clang/test/SemaCXX/addr-of-overloaded-function.cpp
: 'RUN: at line 3';   ...build/bin/clang -cc1 -internal-isystem ...build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -verify -std=c++11 ...clang/test/SemaCXX/addr-of-overloaded-function.cpp
--
Exit Code: 1

Command Output (stderr):
--
error: 'warning' diagnostics expected but not seen: 
  File ...clang/test/SemaCXX/addr-of-overloaded-function.cpp Line 191: incompatible function pointer types assigning to 'void (*)(int, int)' from 'void (*)(int)'
error: 'warning' diagnostics seen but not expected: 
  File ...clang/test/SemaCXX/addr-of-overloaded-function.cpp Line 191: incompatible function pointer types assigning to 'void (*)(double)' from 'void (*)(int)'
2 errors generated.

--

********************
FAIL: Clang :: SemaObjCXX/noescape.mm (11344 of 16808)
******************** TEST 'Clang :: SemaObjCXX/noescape.mm' FAILED ********************
Script:
--
: 'RUN: at line 1';   ...build/bin/clang -cc1 -internal-isystem ...build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -verify -fblocks -std=c++11 ...clang/test/SemaObjCXX/noescape.mm
: 'RUN: at line 2';   ...build/bin/clang -cc1 -internal-isystem ...build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -verify -fblocks -std=c++1z ...clang/test/SemaObjCXX/noescape.mm
--
Exit Code: 1

Command Output (stderr):
--
error: 'error' diagnostics expected but not seen: 
  File ...clang/test/SemaObjCXX/noescape.mm Line 77: assigning to 'void (*)(__attribute__((noescape)) int *)' from incompatible type 'void (*)(int *)'
error: 'warning' diagnostics seen but not expected: 
  File ...clang/test/SemaObjCXX/noescape.mm Line 77: incompatible function pointer types assigning to 'void (*)(__attribute__((noescape)) int *)' from 'void (*)(int *)'
2 errors generated.

--

********************
FAIL: Clang :: SemaObjCXX/nullability-pragmas.mm (11349 of 16808)
******************** TEST 'Clang :: SemaObjCXX/nullability-pragmas.mm' FAILED ********************
Script:
--
: 'RUN: at line 1';   ...build/bin/clang -cc1 -internal-isystem ...build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -fblocks -I ...clang/test/SemaObjCXX/Inputs ...clang/test/SemaObjCXX/nullability-pragmas.mm -verify
--
Exit Code: 1

Command Output (stderr):
--
error: 'error' diagnostics expected but not seen: 
  File ...clang/test/SemaObjCXX/nullability-pragmas.mm Line 35: assigning to 'float *' from incompatible type 'int_ptr _Nonnull' (aka 'int *')
  File ...clang/test/SemaObjCXX/nullability-pragmas.mm Line 39: assigning to 'float *' from incompatible type 'int * _Nonnull'
  File ...clang/test/SemaObjCXX/nullability-pragmas.mm Line 40: assigning to 'float *' from incompatible type 'int * _Null_unspecified'
error: 'warning' diagnostics seen but not expected: 
  File ...clang/test/SemaObjCXX/nullability-pragmas.mm Line 35: incompatible pointer types assigning to 'float *' from 'int_ptr _Nonnull' (aka 'int *')
  File ...clang/test/SemaObjCXX/nullability-pragmas.mm Line 39: incompatible pointer types assigning to 'float *' from 'int * _Nonnull'
  File ...clang/test/SemaObjCXX/nullability-pragmas.mm Line 40: incompatible pointer types assigning to 'float *' from 'int * _Null_unspecified'
6 errors generated.

--

********************
FAIL: Clang :: SemaObjCXX/parameterized_classes_subst.mm (11380 of 16808)
******************** TEST 'Clang :: SemaObjCXX/parameterized_classes_subst.mm' FAILED ********************
Script:
--
: 'RUN: at line 1';   ...build/bin/clang -cc1 -internal-isystem ...build/lib/clang/11.0.0/include -nostdsysteminc -fblocks -fsyntax-only -std=c++11 ...clang/test/SemaObjCXX/parameterized_classes_subst.mm -verify
--
Exit Code: 1

Command Output (stderr):
--
error: 'error' diagnostics expected but not seen: 
  File ...clang/test/SemaObjCXX/parameterized_classes_subst.mm Line 252: from incompatible type 'NSString **'
  File ...clang/test/SemaObjCXX/parameterized_classes_subst.mm Line 253: from incompatible type 'id *'
  File ...clang/test/SemaObjCXX/parameterized_classes_subst.mm Line 260: from incompatible type 'Window **'
error: 'warning' diagnostics seen but not expected: 
  File ...clang/test/SemaObjCXX/parameterized_classes_subst.mm Line 252: incompatible pointer types assigning to 'int *' from 'NSString **'
  File ...clang/test/SemaObjCXX/parameterized_classes_subst.mm Line 253: incompatible pointer types assigning to 'int *' from 'id *'
  File ...clang/test/SemaObjCXX/parameterized_classes_subst.mm Line 260: incompatible pointer types assigning to 'int *' from 'Window **'
6 errors generated.

--

********************
FAIL: Clang :: SemaTemplate/instantiate-declref.cpp (11592 of 16808)
******************** TEST 'Clang :: SemaTemplate/instantiate-declref.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';   ...build/bin/clang -cc1 -internal-isystem ...build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -verify ...clang/test/SemaTemplate/instantiate-declref.cpp
--
Exit Code: 1

Command Output (stderr):
--
error: 'error' diagnostics expected but not seen: 
  File ...clang/test/SemaTemplate/instantiate-declref.cpp Line 53: incompatible
error: 'warning' diagnostics seen but not expected: 
  File ...clang/test/SemaTemplate/instantiate-declref.cpp Line 53: incompatible pointer types assigning to 'int *' from 'float *'
2 errors generated.

--

********************
FAIL: Clang :: SemaTemplate/instantiate-member-class.cpp (11611 of 16808)
******************** TEST 'Clang :: SemaTemplate/instantiate-member-class.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';   ...build/bin/clang -cc1 -internal-isystem ...build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -verify ...clang/test/SemaTemplate/instantiate-member-class.cpp
: 'RUN: at line 2';   ...build/bin/clang -cc1 -internal-isystem ...build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -verify -std=c++98 ...clang/test/SemaTemplate/instantiate-member-class.cpp
: 'RUN: at line 3';   ...build/bin/clang -cc1 -internal-isystem ...build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -verify -std=c++11 ...clang/test/SemaTemplate/instantiate-member-class.cpp
--
Exit Code: 1

Command Output (stderr):
--
error: 'error' diagnostics expected but not seen: 
  File ...clang/test/SemaTemplate/instantiate-member-class.cpp Line 46: assigning to 'X<int>::C *' from incompatible type 'X<float>::C *'
  File ...clang/test/SemaTemplate/instantiate-member-class.cpp Line 47: assigning to 'X<int>::X<int> *' from incompatible type 'X<float>::X<float> *'
error: 'warning' diagnostics seen but not expected: 
  File ...clang/test/SemaTemplate/instantiate-member-class.cpp Line 46: incompatible pointer types assigning to 'X<int>::C *' from 'X<float>::C *'
  File ...clang/test/SemaTemplate/instantiate-member-class.cpp Line 47: incompatible pointer types assigning to 'X<int>::X<int> *' from 'X<float>::X<float> *'
4 errors generated.

--

********************
FAIL: Clang :: SemaTemplate/member-access-expr.cpp (11657 of 16808)
******************** TEST 'Clang :: SemaTemplate/member-access-expr.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';   ...build/bin/clang -cc1 -internal-isystem ...build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -verify ...clang/test/SemaTemplate/member-access-expr.cpp
: 'RUN: at line 2';   ...build/bin/clang -cc1 -internal-isystem ...build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -verify -std=c++98 ...clang/test/SemaTemplate/member-access-expr.cpp
: 'RUN: at line 3';   ...build/bin/clang -cc1 -internal-isystem ...build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -verify -std=c++11 ...clang/test/SemaTemplate/member-access-expr.cpp
--
Exit Code: 1

Command Output (stderr):
--
error: 'error' diagnostics expected but not seen: 
  File ...clang/test/SemaTemplate/member-access-expr.cpp Line 159: assigning to 'test6::B *' from incompatible type 'test6::A *
error: 'warning' diagnostics seen but not expected: 
  File ...clang/test/SemaTemplate/member-access-expr.cpp Line 159: incompatible pointer types assigning to 'test6::B *' from 'test6::A *'
2 errors generated.

Also I guess checkPointerTypesForAssignment should be changed so that it works for references too...

Ah, yes, we're laxer about these things in C than we are in C++. If we do this, we'll need to go through DiagnoseAssignmentResult and make sure that everything (except Compatible, which we'll never pass) triggers an error in C++ mode.

Is there a good reason to just do this for pointer types instead of unconditionally calling CheckAssignmentConstraints? It'd be nice to take advantage of any specialized diagnostics we have for C/ObjC/whatever in C++ mode, and that can apply to a lot of types that aren't pointer types.

It looks like there's already some type analysis in DiagnoseAssignmentResult to get a specialized diagnostic for certain cases of function-pointer assignment. That could probably be easily moved into CheckAssignmentConstraints by just adding a few more cases to AssignConvertResult.

And yeah, it's possible that we'll need to teach that function about some C++ cases that it currently never sees. But I don't think that needs to include references, because IIRC reference-binding doesn't go through ImplicitConversionSequence.

Anastasia updated this revision to Diff 244691.Feb 14 2020, 9:30 AM
  • Switched to using CheckAssignmentConstraints
  • Duplicated all extensions and warnings as errors for C++ mode
  • Added IncompatibleFunctionPointer

It looks like there's already some type analysis in DiagnoseAssignmentResult to get a specialized diagnostic for certain cases of function-pointer assignment. That could probably be easily moved into CheckAssignmentConstraints by just adding a few more cases to AssignConvertResult.

One interesting effect I get after modifying this that some extra tests in C mode started to report function pointer instead of generic pointer warning. I feel this is because in checkPointerTypesForAssignment we use canonical types and in DiagnoseAssignmentResult we don't.

Perhaps this way is better? I can update the test if so and then finalize some other bits.

FAIL: Clang :: Sema/block-return.c (9341 of 16808)
******************** TEST 'Clang :: Sema/block-return.c' FAILED ********************
Script:
--
: 'RUN: at line 1';   <...>build/bin/clang -cc1 -internal-isystem <...>build/lib/clang/11.0.0/include -nostdsysteminc -Wno-int-to-pointer-cast -pedantic -fsyntax-only <...>clang/test/Sema/block-return.c -verify -fblocks
--
Exit Code: 1

Command Output (stderr):
--
error: 'warning' diagnostics expected but not seen: 
  File <...>clang/test/Sema/block-return.c Line 82: incompatible pointer types initializing 'int (*)(const char *)' with an expression of type 'int (char *)'
error: 'warning' diagnostics seen but not expected: 
  File <...>clang/test/Sema/block-return.c Line 82: incompatible function pointer types initializing 'int (*)(const char *)' with an expression of type 'int (char *)'
2 errors generated.

--

********************
FAIL: Clang :: Sema/callingconv-ms_abi.c (9396 of 16808)
******************** TEST 'Clang :: Sema/callingconv-ms_abi.c' FAILED ********************
Script:
--
: 'RUN: at line 1';   <...>build/bin/clang -cc1 -internal-isystem <...>build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -verify -triple x86_64-pc-win32 <...>clang/test/Sema/callingconv-ms_abi.c
--
Exit Code: 1

Command Output (stderr):
--
error: 'warning' diagnostics expected but not seen: 
  File <...>clang/test/Sema/callingconv-ms_abi.c Line 7: incompatible pointer types
  File <...>clang/test/Sema/callingconv-ms_abi.c Line 9: incompatible pointer types
error: 'warning' diagnostics seen but not expected: 
  File <...>clang/test/Sema/callingconv-ms_abi.c Line 7: incompatible function pointer types initializing 'void (*)(void)' with an expression of type 'void (void) __attribute__((sysv_abi))'
  File <...>clang/test/Sema/callingconv-ms_abi.c Line 9: incompatible function pointer types initializing 'void (*)(void) __attribute__((sysv_abi))' with an expression of type 'void (void) __attribute__((ms_abi))'
4 errors generated.

--

********************
FAIL: Clang :: Sema/callingconv-sysv_abi.c (9397 of 16808)
******************** TEST 'Clang :: Sema/callingconv-sysv_abi.c' FAILED ********************
Script:
--
: 'RUN: at line 1';   <...>build/bin/clang -cc1 -internal-isystem <...>build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -verify -triple x86_64-pc-linux-gnu <...>clang/test/Sema/callingconv-sysv_abi.c
--
Exit Code: 1

Command Output (stderr):
--
error: 'warning' diagnostics expected but not seen: 
  File <...>clang/test/Sema/callingconv-sysv_abi.c Line 4: incompatible pointer types
  File <...>clang/test/Sema/callingconv-sysv_abi.c Line 9: incompatible pointer types
error: 'warning' diagnostics seen but not expected: 
  File <...>clang/test/Sema/callingconv-sysv_abi.c Line 4: incompatible function pointer types initializing 'void (*)(void)' with an expression of type 'void (void) __attribute__((ms_abi))'
  File <...>clang/test/Sema/callingconv-sysv_abi.c Line 9: incompatible function pointer types initializing 'void (*)(void) __attribute__((ms_abi))' with an expression of type 'void (void) __attribute__((sysv_abi))'
4 errors generated.

--

********************
FAIL: Clang :: Sema/callingconv.c (9398 of 16808)
******************** TEST 'Clang :: Sema/callingconv.c' FAILED ********************
Script:
--
: 'RUN: at line 1';   <...>build/bin/clang -cc1 -internal-isystem <...>build/lib/clang/11.0.0/include -nostdsysteminc <...>clang/test/Sema/callingconv.c -fsyntax-only -triple i386-unknown-unknown -verify
: 'RUN: at line 2';   <...>build/bin/clang -cc1 -internal-isystem <...>build/lib/clang/11.0.0/include -nostdsysteminc <...>clang/test/Sema/callingconv.c -fsyntax-only -triple i386-unknown-unknown -fms-compatibility -DWIN -verify
--
Exit Code: 1

Command Output (stderr):
--
error: 'warning' diagnostics expected but not seen: 
  File <...>clang/test/Sema/callingconv.c Line 34: incompatible pointer types
error: 'warning' diagnostics seen but not expected: 
  File <...>clang/test/Sema/callingconv.c Line 34: incompatible function pointer types initializing 'void (*)(void) __attribute__((cdecl))' with an expression of type 'void (void) __attribute__((fastcall))'
2 errors generated.

--

********************
FAIL: Clang :: Sema/pass-object-size.c (9608 of 16808)
******************** TEST 'Clang :: Sema/pass-object-size.c' FAILED ********************
Script:
--
: 'RUN: at line 1';   <...>build/bin/clang -cc1 -internal-isystem <...>build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -verify <...>clang/test/Sema/pass-object-size.c -triple x86_64-linux-gnu -Wincompatible-pointer-types
--
Exit Code: 1

Command Output (stderr):
--
error: 'warning' diagnostics expected but not seen: 
  File <...>clang/test/Sema/pass-object-size.c Line 47: incompatible pointer types initializing 'void (*)(void *)' with an expression of type '<overloaded function type>'
  File <...>clang/test/Sema/pass-object-size.c Line 48: incompatible pointer types initializing 'void (*)(void *)' with an expression of type '<overloaded function type>'
error: 'warning' diagnostics seen but not expected: 
  File <...>clang/test/Sema/pass-object-size.c Line 47: incompatible function pointer types initializing 'void (*)(void *)' with an expression of type '<overloaded function type>'
  File <...>clang/test/Sema/pass-object-size.c Line 48: incompatible function pointer types initializing 'void (*)(void *)' with an expression of type '<overloaded function type>'
4 errors generated.

--

********************
FAIL: Clang :: Sema/overloadable.c (9609 of 16808)
******************** TEST 'Clang :: Sema/overloadable.c' FAILED ********************
Script:
--
: 'RUN: at line 1';   <...>build/bin/clang -cc1 -internal-isystem <...>build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -verify <...>clang/test/Sema/overloadable.c -Wincompatible-pointer-types
--
Exit Code: 1

Command Output (stderr):
--
error: 'error' diagnostics expected but not seen: 
  File <...>clang/test/Sema/overloadable.c Line 29: call to 'accept_funcptr' is ambiguous
error: 'error' diagnostics seen but not expected: 
  File <...>clang/test/Sema/overloadable.c Line 29: no matching function for call to 'accept_funcptr'
error: 'warning' diagnostics expected but not seen: 
  File <...>clang/test/Sema/overloadable.c Line 122: incompatible pointer types initializing 'void (*)(void *)' with an expression of type '<overloaded function type>'
  File <...>clang/test/Sema/overloadable.c Line 123: incompatible pointer types initializing 'void (*)(int *)' with an expression of type '<overloaded function type>'
error: 'warning' diagnostics seen but not expected: 
  File <...>clang/test/Sema/overloadable.c Line 122: incompatible function pointer types initializing 'void (*)(void *)' with an expression of type '<overloaded function type>'
  File <...>clang/test/Sema/overloadable.c Line 123: incompatible function pointer types initializing 'void (*)(int *)' with an expression of type '<overloaded function type>'
6 errors generated.

--

********************
FAIL: Clang :: Sema/preserve-call-conv.c (9653 of 16808)
******************** TEST 'Clang :: Sema/preserve-call-conv.c' FAILED ********************
Script:
--
: 'RUN: at line 1';   <...>build/bin/clang -cc1 -internal-isystem <...>build/lib/clang/11.0.0/include -nostdsysteminc <...>clang/test/Sema/preserve-call-conv.c -fsyntax-only -triple x86_64-unknown-unknown -verify
: 'RUN: at line 2';   <...>build/bin/clang -cc1 -internal-isystem <...>build/lib/clang/11.0.0/include -nostdsysteminc <...>clang/test/Sema/preserve-call-conv.c -fsyntax-only -triple arm64-unknown-unknown -verify
: 'RUN: at line 3';   <...>build/bin/clang -cc1 -internal-isystem <...>build/lib/clang/11.0.0/include -nostdsysteminc <...>clang/test/Sema/preserve-call-conv.c -fsyntax-only -triple x86_64-unknown-windows-msvc -verify
: 'RUN: at line 4';   <...>build/bin/clang -cc1 -internal-isystem <...>build/lib/clang/11.0.0/include -nostdsysteminc <...>clang/test/Sema/preserve-call-conv.c -fsyntax-only -triple aarch64-unknown-windows-msvc -verify
: 'RUN: at line 5';   <...>build/bin/clang -cc1 -internal-isystem <...>build/lib/clang/11.0.0/include -nostdsysteminc <...>clang/test/Sema/preserve-call-conv.c -fsyntax-only -triple thumbv7-unknown-windows-msvc -verify
--
Exit Code: 1

Command Output (stderr):
--
error: 'warning' diagnostics expected but not seen: 
  File <...>clang/test/Sema/preserve-call-conv.c Line 17: incompatible pointer types initializing 'void (*)(void *) __attribute__((cdecl))' with an expression of type 'void (void *) __attribute__((preserve_most))'
  File <...>clang/test/Sema/preserve-call-conv.c Line 18: incompatible pointer types initializing 'void (*)(void *)' with an expression of type 'void (void *) __attribute__((preserve_most))'
  File <...>clang/test/Sema/preserve-call-conv.c Line 33: incompatible pointer types initializing 'void (*)(void *) __attribute__((cdecl))' with an expression of type 'void (void *) __attribute__((preserve_all))'
  File <...>clang/test/Sema/preserve-call-conv.c Line 34: incompatible pointer types initializing 'void (*)(void *)' with an expression of type 'void (void *) __attribute__((preserve_all))'
error: 'warning' diagnostics seen but not expected: 
  File <...>clang/test/Sema/preserve-call-conv.c Line 17: incompatible function pointer types initializing 'void (*)(void *) __attribute__((cdecl))' with an expression of type 'void (void *) __attribute__((preserve_most))'
  File <...>clang/test/Sema/preserve-call-conv.c Line 18: incompatible function pointer types initializing 'void (*)(void *)' with an expression of type 'void (void *) __attribute__((preserve_most))'
  File <...>clang/test/Sema/preserve-call-conv.c Line 33: incompatible function pointer types initializing 'void (*)(void *) __attribute__((cdecl))' with an expression of type 'void (void *) __attribute__((preserve_all))'
  File <...>clang/test/Sema/preserve-call-conv.c Line 34: incompatible function pointer types initializing 'void (*)(void *)' with an expression of type 'void (void *) __attribute__((preserve_all))'
8 errors generated.

--

********************
FAIL: Clang :: SemaObjC/comptypes-legal.m (10887 of 16808)
******************** TEST 'Clang :: SemaObjC/comptypes-legal.m' FAILED ********************
Script:
--
: 'RUN: at line 1';   <...>build/bin/clang -cc1 -internal-isystem <...>build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -verify -pedantic <...>clang/test/SemaObjC/comptypes-legal.m
--
Exit Code: 1

Command Output (stderr):
--
error: 'warning' diagnostics expected but not seen: 
  File <...>clang/test/SemaObjC/comptypes-legal.m Line 36: incompatible pointer types sending 'NSObject *(NSObject *, NSObject *)' to parameter of type 'FuncSignature *'
error: 'warning' diagnostics seen but not expected: 
  File <...>clang/test/SemaObjC/comptypes-legal.m Line 36: incompatible function pointer types sending 'NSObject *(NSObject *, NSObject *)' to parameter of type 'FuncSignature *' (aka 'id (*)(NSObject *, Derived *)')
2 errors generated.

--

********************

Testing Time: 438.97s
********************
Failing Tests (8):
    Clang :: Sema/block-return.c
    Clang :: Sema/callingconv-ms_abi.c
    Clang :: Sema/callingconv-sysv_abi.c
    Clang :: Sema/callingconv.c
    Clang :: Sema/overloadable.c
    Clang :: Sema/pass-object-size.c
    Clang :: Sema/preserve-call-conv.c
    Clang :: SemaObjC/comptypes-legal.m

The C diagnostic changes seem like improvements, yeah. The virtue of re-using the same infrastructure across language modes.

clang/lib/Sema/SemaExprCXX.cpp
3930

This assertion seems important; can we make it work?

Anastasia marked an inline comment as done.Feb 17 2020, 3:12 AM
Anastasia added inline comments.
clang/lib/Sema/SemaExprCXX.cpp
3930

Currently DiagnoseAssignmentResult returns true only for Incompatible , However we can change it to return true for all Incompatibel* in C++ mode. So yes it should be doable.

rjmccall added inline comments.Feb 17 2020, 10:00 AM
clang/lib/Sema/SemaExprCXX.cpp
3930

Okay. My guess is it should return true whenever we emit an error rather than a warning (ignoring the effects of things like -Werror, of course).

Anastasia updated this revision to Diff 245164.Feb 18 2020, 7:45 AM
Anastasia retitled this revision from [Sema][C++] Strawman patch to propagate conversion type in order to specialize the diagnostics to [Sema][C++] Propagate conversion type in order to specialize the diagnostics.
  • Updated expected diagnostics for function pointer tests
  • Make DiagnoseAsignmentResult return true for all incompatible cases in C++
rjmccall added inline comments.Feb 19 2020, 7:31 AM
clang/lib/Sema/SemaExpr.cpp
14834

Could you hoist this up to the place where we pick the diagnostic and then make it unconditional in the path that always selects an error?

That's a general comment: we should be setting isInvalid for all the places below where we select an error diagnostic.

Anastasia marked an inline comment as done.Feb 19 2020, 12:07 PM
Anastasia added inline comments.
clang/lib/Sema/SemaExpr.cpp
14834

That's a general comment: we should be setting isInvalid for all the places below where we select an error diagnostic.

If I change to set isInvalid for all error cases I get less diagnostics. I guess it's because we now stop earlier and don't continue to diagnosing in some cases.

FAIL: Clang :: Sema/block-call.c (9327 of 16808)
******************** TEST 'Clang :: Sema/block-call.c' FAILED ********************
Script:
--
: 'RUN: at line 1';   /data/llvm/llvm-forcommits/build/bin/clang -cc1 -internal-isystem /data/llvm/llvm-forcommits/build/lib/clang/11.0.0/include -nostdsysteminc -fsyntax-only -verify /data/llvm/llvm-forcommits/clang/test/Sema/block-call.c -fblocks
--
Exit Code: 1

Command Output (stderr):
--
error: 'error' diagnostics expected but not seen: 
  File /data/llvm/llvm-forcommits/clang/test/Sema/block-call.c Line 36: invalid block pointer conversion assigning to 'int *(^)()' from 'int'
1 error generated.

--

********************
FAIL: Clang :: SemaObjC/arc.m (10804 of 16808)
******************** TEST 'Clang :: SemaObjC/arc.m' FAILED ********************
Script:
--
: 'RUN: at line 1';   /data/llvm/llvm-forcommits/build/bin/clang -cc1 -internal-isystem /data/llvm/llvm-forcommits/build/lib/clang/11.0.0/include -nostdsysteminc -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -verify -Wno-objc-root-class /data/llvm/llvm-forcommits/clang/test/SemaObjC/arc.m
: 'RUN: at line 2';   not /data/llvm/llvm-forcommits/build/bin/clang -cc1 -internal-isystem /data/llvm/llvm-forcommits/build/lib/clang/11.0.0/include -nostdsysteminc -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -Wno-objc-root-class -fdiagnostics-parseable-fixits /data/llvm/llvm-forcommits/clang/test/SemaObjC/arc.m 2>&1
--
Exit Code: 1

Command Output (stderr):
--
error: 'error' diagnostics expected but not seen: 
  File /data/llvm/llvm-forcommits/clang/test/SemaObjC/arc.m Line 117: assigning '__strong id *' to '__autoreleasing id *' changes retain/release properties of pointer
1 error generated.

Yeah, looks like returning true causes the variable to be marked as invalid (not unreasonable, since maybe its type is wrong), which causes downstream diagnostics to be suppressed.

Both test cases should probably be fixed to assign into a different variable so that we continue to test the diagnostic.

Anastasia updated this revision to Diff 245647.Feb 20 2020, 6:56 AM
  • Always set isInvalid for all error cases.
  • Hoist setting isInvalid together with an error diagnostic.
  • Updated more tests.
rjmccall accepted this revision.Feb 20 2020, 7:25 AM

LGTM, thanks!

This revision is now accepted and ready to land.Feb 20 2020, 7:25 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 25 2020, 8:08 AM