[clang] Revert "[clang] Fix-it hint for `++this` -> `++*this` when deref is modifiable" (PR #95833)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 17 12:45:59 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: None (Sirraide)
<details>
<summary>Changes</summary>
Reverts llvm/llvm-project#<!-- -->94159
@<!-- -->zygoloid had some concerns about the implementation of this, which make sense to me, so I’d like to revert this for now so we can have more time to think about how to best approach this (if at all...)
---
Full diff: https://github.com/llvm/llvm-project/pull/95833.diff
7 Files Affected:
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (-3)
- (modified) clang/lib/Sema/SemaExpr.cpp (+2-22)
- (modified) clang/test/C/drs/dr1xx.c (-1)
- (removed) clang/test/Sema/debug-93066.cpp (-49)
- (modified) clang/test/Sema/exprs.c (-2)
- (modified) clang/test/Sema/va_arg_x86_32.c (-1)
- (modified) clang/test/SemaObjCXX/sel-address.mm (-13)
``````````diff
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9b8f5b7e80e7e..8f85371df3b85 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8778,9 +8778,6 @@ def err_typecheck_incomplete_type_not_modifiable_lvalue : Error<
def err_typecheck_lvalue_casts_not_supported : Error<
"assignment to cast is illegal, lvalue casts are not supported">;
-def note_typecheck_add_deref_star_not_modifiable_lvalue : Note<
- "add '*' to dereference it">;
-
def err_typecheck_duplicate_vector_components_not_mlvalue : Error<
"vector is not assignable (contains duplicate components)">;
def err_block_decl_ref_not_modifiable_lvalue : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4db8b4130c3c7..453af8f28f946 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -13288,23 +13288,6 @@ enum {
ConstUnknown, // Keep as last element
};
-static void MaybeSuggestDerefFixIt(Sema &S, const Expr *E, SourceLocation Loc) {
- ExprResult Deref;
- Expr *TE = const_cast<Expr *>(E);
- {
- Sema::TentativeAnalysisScope Trap(S);
- Deref = S.ActOnUnaryOp(S.getCurScope(), Loc, tok::star, TE);
- }
- if (Deref.isUsable() &&
- Deref.get()->isModifiableLvalue(S.Context, &Loc) == Expr::MLV_Valid &&
- !E->getType()->isObjCObjectPointerType()) {
- S.Diag(E->getBeginLoc(),
- diag::note_typecheck_add_deref_star_not_modifiable_lvalue)
- << E->getSourceRange()
- << FixItHint::CreateInsertion(E->getBeginLoc(), "*");
- }
-}
-
/// Emit the "read-only variable not assignable" error and print notes to give
/// more information about why the variable is not assignable, such as pointing
/// to the declaration of a const variable, showing that a method is const, or
@@ -13399,7 +13382,6 @@ static void DiagnoseConstAssignment(Sema &S, const Expr *E,
if (!DiagnosticEmitted) {
S.Diag(Loc, diag::err_typecheck_assign_const)
<< ExprRange << ConstVariable << VD << VD->getType();
- MaybeSuggestDerefFixIt(S, E, Loc);
DiagnosticEmitted = true;
}
S.Diag(VD->getLocation(), diag::note_typecheck_assign_const)
@@ -13620,12 +13602,10 @@ static bool CheckForModifiableLvalue(Expr *E, SourceLocation Loc, Sema &S) {
SourceRange Assign;
if (Loc != OrigLoc)
Assign = SourceRange(OrigLoc, OrigLoc);
- if (NeedType) {
+ if (NeedType)
S.Diag(Loc, DiagID) << E->getType() << E->getSourceRange() << Assign;
- } else {
+ else
S.Diag(Loc, DiagID) << E->getSourceRange() << Assign;
- MaybeSuggestDerefFixIt(S, E, Loc);
- }
return true;
}
diff --git a/clang/test/C/drs/dr1xx.c b/clang/test/C/drs/dr1xx.c
index 20e953b2c20ac..47538e44428c3 100644
--- a/clang/test/C/drs/dr1xx.c
+++ b/clang/test/C/drs/dr1xx.c
@@ -296,7 +296,6 @@ void dr126(void) {
*/
*object = 12; /* ok */
++object; /* expected-error {{cannot assign to variable 'object' with const-qualified type 'const IP' (aka 'int *const')}} */
- /* expected-note at -1 {{add '*' to dereference it}} */
}
/* WG14 DR128: yes
diff --git a/clang/test/Sema/debug-93066.cpp b/clang/test/Sema/debug-93066.cpp
deleted file mode 100644
index e64d378e6f90d..0000000000000
--- a/clang/test/Sema/debug-93066.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
-
-struct S {
- void f() {
- ++this; // expected-error {{expression is not assignable}}
- // expected-note at -1 {{add '*' to dereference it}}
- }
-
- void g() const {
- ++this; // expected-error {{expression is not assignable}}
- }
-};
-
-void f(int* a, int* const b, const int* const c, __UINTPTR_TYPE__ d) {
- // expected-note at -1 {{variable 'b' declared const here}}
- // expected-note at -2 {{variable 'c' declared const here}}
- (int*)d = 4; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
- // expected-note at -1 {{add '*' to dereference it}}
-
- ++a;
- ++b; // expected-error {{cannot assign to variable 'b' with const-qualified type 'int *const'}}
- // expected-note at -1 {{add '*' to dereference it}}
- ++c; // expected-error {{cannot assign to variable 'c' with const-qualified type 'const int *const'}}
-
- reinterpret_cast<int*>(42) += 3; // expected-error {{expression is not assignable}}
- // expected-note at -1 {{add '*' to dereference it}}
-
- const int x = 42;
- (const_cast<int*>(&x)) += 3; // expected-error {{expression is not assignable}}
- // expected-note at -1 {{add '*' to dereference it}}
-}
-
-template <typename T>
-void f(T& t) {
- // expected-note@* 2 {{variable 't' declared const here}}
- ++t;
- // expected-error at -1 {{cannot assign to variable 't' with const-qualified type 'int *const &'}}
- // expected-error at -2 {{cannot assign to variable 't' with const-qualified type 'const int *const &'}}
- // expected-note at -3 {{add '*' to dereference it}}
-}
-
-void g() {
- int* a;
- int* const b = a;
- const int* const c = a;
- f(a);
- f(b); // expected-note {{in instantiation of function template specialization 'f<int *const>' requested here}}
- f(c); // expected-note {{in instantiation of function template specialization 'f<const int *const>' requested here}}
-}
diff --git a/clang/test/Sema/exprs.c b/clang/test/Sema/exprs.c
index a5b7268f4f527..3203d961dd0a4 100644
--- a/clang/test/Sema/exprs.c
+++ b/clang/test/Sema/exprs.c
@@ -65,10 +65,8 @@ void test4(void) {
void test5(int *X, float *P) {
(float*)X = P; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
- // expected-note at -1 {{add '*' to dereference it}}
#define FOO ((float*) X)
FOO = P; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
- // expected-note at -1 {{add '*' to dereference it}}
}
void test6(void) {
diff --git a/clang/test/Sema/va_arg_x86_32.c b/clang/test/Sema/va_arg_x86_32.c
index 55d21f787a6f0..86a6a8881f54b 100644
--- a/clang/test/Sema/va_arg_x86_32.c
+++ b/clang/test/Sema/va_arg_x86_32.c
@@ -2,6 +2,5 @@
int a(void) {
__builtin_va_arg((char*)0, int); // expected-error {{expression is not assignable}}
- // expected-note at -1 {{add '*' to dereference it}}
__builtin_va_arg((void*){0}, int); // expected-error {{first argument to 'va_arg' is of type 'void *'}}
}
diff --git a/clang/test/SemaObjCXX/sel-address.mm b/clang/test/SemaObjCXX/sel-address.mm
index d69f7055035d6..e5661af341691 100644
--- a/clang/test/SemaObjCXX/sel-address.mm
+++ b/clang/test/SemaObjCXX/sel-address.mm
@@ -9,20 +9,7 @@ void h() {
SEL s = @selector(dealloc);
SEL* ps = &s;
- /*
- FIXME: https://github.com/llvm/llvm-project/pull/94159
-
- TLDR; This is about inserting '*' to deref.
-
- This would assign the value of s to the SEL object pointed to by
- @selector(dealloc). However, in Objective-C, selectors are not pointers,
- they are special compile-time constructs representing method names, and
- they are immutable, so you cannot assign values to them.
-
- Therefore, this syntax is not valid for selectors in Objective-C.
- */
@selector(dealloc) = s; // expected-error {{expression is not assignable}}
- // expected-note at -1 {{add '*' to dereference it}}
SEL* ps2 = &@selector(dealloc);
``````````
</details>
https://github.com/llvm/llvm-project/pull/95833
More information about the cfe-commits
mailing list