[PATCH] D74116: [Sema][C++] Strawman patch to propagate conversion type in order to specialize the diagnostics
Anastasia Stulova via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 12 04:50:35 PST 2020
Anastasia updated this revision to Diff 244135.
Anastasia added a comment.
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...
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D74116/new/
https://reviews.llvm.org/D74116
Files:
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/addr-of-overloaded-function.cpp
Index: clang/test/SemaCXX/addr-of-overloaded-function.cpp
===================================================================
--- clang/test/SemaCXX/addr-of-overloaded-function.cpp
+++ clang/test/SemaCXX/addr-of-overloaded-function.cpp
@@ -182,19 +182,19 @@
void parameter_number() {
void (*ptr1)(int, int) = &fun; // expected-error {{cannot initialize a variable of type 'void (*)(int, int)' with an rvalue of type 'void (*)(int)': different number of parameters (2 vs 1)}}
void (*ptr2)(int, int);
- ptr2 = &fun; // expected-error {{assigning to 'void (*)(int, int)' from incompatible type 'void (*)(int)': different number of parameters (2 vs 1)}}
+ ptr2 = &fun; // expected-warning {{incompatible function pointer types assigning to 'void (*)(int, int)' from 'void (*)(int)'}}
}
void parameter_mismatch() {
void (*ptr1)(double) = &fun; // expected-error {{cannot initialize a variable of type 'void (*)(double)' with an rvalue of type 'void (*)(int)': type mismatch at 1st parameter ('double' vs 'int')}}
void (*ptr2)(double);
- ptr2 = &fun; // expected-error {{assigning to 'void (*)(double)' from incompatible type 'void (*)(int)': type mismatch at 1st parameter ('double' vs 'int')}}
+ ptr2 = &fun; // expected-warning {{incompatible function pointer types assigning to 'void (*)(int, int)' from 'void (*)(int)'}}
}
void return_type_test() {
int (*ptr1)(int) = &fun; // expected-error {{cannot initialize a variable of type 'int (*)(int)' with an rvalue of type 'void (*)(int)': different return type ('int' vs 'void')}}
int (*ptr2)(int);
- ptr2 = &fun; // expected-error {{assigning to 'int (*)(int)' from incompatible type 'void (*)(int)': different return type ('int' vs 'void')}}
+ ptr2 = &fun; // expected-warning {{incompatible function pointer types assigning to 'int (*)(int)' from 'void (*)(int)'}}
}
int foo(double x, double y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}}
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -3872,10 +3872,17 @@
llvm_unreachable("Cannot perform an ellipsis conversion");
case ImplicitConversionSequence::BadConversion:
+ Sema::AssignConvertType ConvTy = Compatible;
+ if (ToType.getCanonicalType()->isPointerType() &&
+ From->getType()->isPointerType())
+ ConvTy = checkPointerTypesForAssignment(*this, ToType.getCanonicalType(),
+ From->getType().getCanonicalType());
bool Diagnosed =
- DiagnoseAssignmentResult(Incompatible, From->getExprLoc(), ToType,
+ DiagnoseAssignmentResult(ConvTy == Compatible ? Incompatible : ConvTy,
+ From->getExprLoc(), ToType,
From->getType(), From, Action);
- assert(Diagnosed && "failed to diagnose bad conversion"); (void)Diagnosed;
+ //assert(Diagnosed && "failed to diagnose bad conversion");
+ (void)Diagnosed;
return ExprError();
}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -8018,7 +8018,7 @@
// routine is it effectively iqnores the qualifiers on the top level pointee.
// This circumvents the usual type rules specified in 6.2.7p1 & 6.7.5.[1-3].
// FIXME: add a couple examples in this comment.
-static Sema::AssignConvertType
+Sema::AssignConvertType
checkPointerTypesForAssignment(Sema &S, QualType LHSType, QualType RHSType) {
assert(LHSType.isCanonical() && "LHS not canonicalized!");
assert(RHSType.isCanonical() && "RHS not canonicalized!");
Index: clang/include/clang/Sema/Sema.h
===================================================================
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -230,6 +230,8 @@
void threadSafetyCleanup(BeforeSet* Cache);
}
+
+
// FIXME: No way to easily map from TemplateTypeParmTypes to
// TemplateTypeParmDecls, so we have this horrible PointerUnion.
typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType*, NamedDecl*>,
@@ -12138,6 +12140,8 @@
MakeDeductionFailureInfo(ASTContext &Context, Sema::TemplateDeductionResult TDK,
sema::TemplateDeductionInfo &Info);
+
+
/// Contains a late templated function.
/// Will be parsed at the end of the translation unit, used by Sema & Parser.
struct LateParsedTemplate {
@@ -12147,6 +12151,9 @@
};
} // end namespace clang
+clang::Sema::AssignConvertType checkPointerTypesForAssignment(clang::Sema &S, clang::QualType LHSType,
+ clang::QualType RHSType);
+
namespace llvm {
// Hash a FunctionDeclAndLoc by looking at both its FunctionDecl and its
// SourceLocation.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74116.244135.patch
Type: text/x-patch
Size: 4991 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200212/32ea04fa/attachment-0001.bin>
More information about the cfe-commits
mailing list