Skip to content

Commit 2d6a39f

Browse files
author
huqizhi
committed
[Clang][Sema] fix crash of attribute transform
1 parent d5c9d40 commit 2d6a39f

File tree

4 files changed

+233
-5
lines changed

4 files changed

+233
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,211 @@ Improvements to Clang's time-trace
103103

104104
Bug Fixes in This Version
105105
-------------------------
106+
<<<<<<< HEAD
107+
=======
108+
- Fixed an issue where a class template specialization whose declaration is
109+
instantiated in one module and whose definition is instantiated in another
110+
module may end up with members associated with the wrong declaration of the
111+
class, which can result in miscompiles in some cases.
112+
- Fix crash on use of a variadic overloaded operator.
113+
(`#42535 <https://github.com/llvm/llvm-project/issues/42535>`_)
114+
- Fix a hang on valid C code passing a function type as an argument to
115+
``typeof`` to form a function declaration.
116+
(`#64713 <https://github.com/llvm/llvm-project/issues/64713>`_)
117+
- Clang now reports missing-field-initializers warning for missing designated
118+
initializers in C++.
119+
(`#56628 <https://github.com/llvm/llvm-project/issues/56628>`_)
120+
- Clang now respects ``-fwrapv`` and ``-ftrapv`` for ``__builtin_abs`` and
121+
``abs`` builtins.
122+
(`#45129 <https://github.com/llvm/llvm-project/issues/45129>`_,
123+
`#45794 <https://github.com/llvm/llvm-project/issues/45794>`_)
124+
- Fixed an issue where accesses to the local variables of a coroutine during
125+
``await_suspend`` could be misoptimized, including accesses to the awaiter
126+
object itself.
127+
(`#56301 <https://github.com/llvm/llvm-project/issues/56301>`_)
128+
The current solution may bring performance regressions if the awaiters have
129+
non-static data members. See
130+
`#64945 <https://github.com/llvm/llvm-project/issues/64945>`_ for details.
131+
- Clang now prints unnamed members in diagnostic messages instead of giving an
132+
empty ''. Fixes
133+
(`#63759 <https://github.com/llvm/llvm-project/issues/63759>`_)
134+
- Fix crash in __builtin_strncmp and related builtins when the size value
135+
exceeded the maximum value representable by int64_t. Fixes
136+
(`#64876 <https://github.com/llvm/llvm-project/issues/64876>`_)
137+
- Fixed an assertion if a function has cleanups and fatal erors.
138+
(`#48974 <https://github.com/llvm/llvm-project/issues/48974>`_)
139+
- Clang now emits an error if it is not possible to deduce array size for a
140+
variable with incomplete array type.
141+
(`#37257 <https://github.com/llvm/llvm-project/issues/37257>`_)
142+
- Clang's ``-Wunused-private-field`` no longer warns on fields whose type is
143+
declared with ``[[maybe_unused]]``.
144+
(`#61334 <https://github.com/llvm/llvm-project/issues/61334>`_)
145+
- For function multi-versioning using the ``target``, ``target_clones``, or
146+
``target_version`` attributes, remove comdat for internal linkage functions.
147+
(`#65114 <https://github.com/llvm/llvm-project/issues/65114>`_)
148+
- Clang now reports ``-Wformat`` for bool value and char specifier confusion
149+
in scanf. Fixes
150+
(`#64987 <https://github.com/llvm/llvm-project/issues/64987>`_)
151+
- Support MSVC predefined macro expressions in constant expressions and in
152+
local structs.
153+
- Correctly parse non-ascii identifiers that appear immediately after a line splicing
154+
(`#65156 <https://github.com/llvm/llvm-project/issues/65156>`_)
155+
- Clang no longer considers the loss of ``__unaligned`` qualifier from objects as
156+
an invalid conversion during method function overload resolution.
157+
- Fix lack of comparison of declRefExpr in ASTStructuralEquivalence
158+
(`#66047 <https://github.com/llvm/llvm-project/issues/66047>`_)
159+
- Fix parser crash when dealing with ill-formed objective C++ header code. Fixes
160+
(`#64836 <https://github.com/llvm/llvm-project/issues/64836>`_)
161+
- Fix crash in implicit conversions from initialize list to arrays of unknown
162+
bound for C++20. Fixes
163+
(`#62945 <https://github.com/llvm/llvm-project/issues/62945>`_)
164+
- Clang now allows an ``_Atomic`` qualified integer in a switch statement. Fixes
165+
(`#65557 <https://github.com/llvm/llvm-project/issues/65557>`_)
166+
- Fixes crash when trying to obtain the common sugared type of
167+
`decltype(instantiation-dependent-expr)`.
168+
Fixes (`#67603 <https://github.com/llvm/llvm-project/issues/67603>`_)
169+
- Fixes a crash caused by a multidimensional array being captured by a lambda
170+
(`#67722 <https://github.com/llvm/llvm-project/issues/67722>`_).
171+
- Fixes a crash when instantiating a lambda with requires clause.
172+
(`#64462 <https://github.com/llvm/llvm-project/issues/64462>`_)
173+
- Fixes a regression where the ``UserDefinedLiteral`` was not properly preserved
174+
while evaluating consteval functions. (`#63898 <https://github.com/llvm/llvm-project/issues/63898>`_).
175+
- Fix a crash when evaluating value-dependent structured binding
176+
variables at compile time.
177+
Fixes (`#67690 <https://github.com/llvm/llvm-project/issues/67690>`_)
178+
- Fixes a ``clang-17`` regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF``
179+
cannot be used with ``Release`` mode builds. (`#68237 <https://github.com/llvm/llvm-project/issues/68237>`_).
180+
- Fix crash in evaluating ``constexpr`` value for invalid template function.
181+
Fixes (`#68542 <https://github.com/llvm/llvm-project/issues/68542>`_)
182+
- Clang will correctly evaluate ``noexcept`` expression for template functions
183+
of template classes. Fixes
184+
(`#68543 <https://github.com/llvm/llvm-project/issues/68543>`_,
185+
`#42496 <https://github.com/llvm/llvm-project/issues/42496>`_,
186+
`#77071 <https://github.com/llvm/llvm-project/issues/77071>`_,
187+
`#77411 <https://github.com/llvm/llvm-project/issues/77411>`_)
188+
- Fixed an issue when a shift count larger than ``__INT64_MAX__``, in a right
189+
shift operation, could result in missing warnings about
190+
``shift count >= width of type`` or internal compiler error.
191+
- Fixed an issue with computing the common type for the LHS and RHS of a `?:`
192+
operator in C. No longer issuing a confusing diagnostic along the lines of
193+
"incompatible operand types ('foo' and 'foo')" with extensions such as matrix
194+
types. Fixes (`#69008 <https://github.com/llvm/llvm-project/issues/69008>`_)
195+
- Clang no longer permits using the `_BitInt` types as an underlying type for an
196+
enumeration as specified in the C23 Standard.
197+
Fixes (`#69619 <https://github.com/llvm/llvm-project/issues/69619>`_)
198+
- Fixed an issue when a shift count specified by a small constant ``_BitInt()``,
199+
in a left shift operation, could result in a faulty warnings about
200+
``shift count >= width of type``.
201+
- Clang now accepts anonymous members initialized with designated initializers
202+
inside templates.
203+
Fixes (`#65143 <https://github.com/llvm/llvm-project/issues/65143>`_)
204+
- Fix crash in formatting the real/imaginary part of a complex lvalue.
205+
Fixes (`#69218 <https://github.com/llvm/llvm-project/issues/69218>`_)
206+
- No longer use C++ ``thread_local`` semantics in C23 when using
207+
``thread_local`` instead of ``_Thread_local``.
208+
Fixes (`#70068 <https://github.com/llvm/llvm-project/issues/70068>`_) and
209+
(`#69167 <https://github.com/llvm/llvm-project/issues/69167>`_)
210+
- Fix crash in evaluating invalid lambda expression which forget capture this.
211+
Fixes (`#67687 <https://github.com/llvm/llvm-project/issues/67687>`_)
212+
- Fix crash from constexpr evaluator evaluating uninitialized arrays as rvalue.
213+
Fixes (`#67317 <https://github.com/llvm/llvm-project/issues/67317>`_)
214+
- Clang now properly diagnoses use of stand-alone OpenMP directives after a
215+
label (including ``case`` or ``default`` labels).
216+
- Fix compiler memory leak for enums with underlying type larger than 64 bits.
217+
Fixes (`#78311 <https://github.com/llvm/llvm-project/pull/78311>`_)
218+
219+
Before:
220+
221+
.. code-block:: c++
222+
223+
label:
224+
#pragma omp barrier // ok
225+
226+
After:
227+
228+
.. code-block:: c++
229+
230+
label:
231+
#pragma omp barrier // error: '#pragma omp barrier' cannot be an immediate substatement
232+
233+
- Fixed an issue that a benign assertion might hit when instantiating a pack expansion
234+
inside a lambda. (`#61460 <https://github.com/llvm/llvm-project/issues/61460>`_)
235+
- Fix crash during instantiation of some class template specializations within class
236+
templates. Fixes (`#70375 <https://github.com/llvm/llvm-project/issues/70375>`_)
237+
- Fix crash during code generation of C++ coroutine initial suspend when the return
238+
type of await_resume is not trivially destructible.
239+
Fixes (`#63803 <https://github.com/llvm/llvm-project/issues/63803>`_)
240+
- ``__is_trivially_relocatable`` no longer returns true for non-object types
241+
such as references and functions.
242+
Fixes (`#67498 <https://github.com/llvm/llvm-project/issues/67498>`_)
243+
- Fix crash when the object used as a ``static_assert`` message has ``size`` or ``data`` members
244+
which are not member functions.
245+
- Support UDLs in ``static_assert`` message.
246+
- Fixed false positive error emitted by clang when performing qualified name
247+
lookup and the current class instantiation has dependent bases.
248+
Fixes (`#13826 <https://github.com/llvm/llvm-project/issues/13826>`_)
249+
- Fix a ``clang-17`` regression where a templated friend with constraints is not
250+
properly applied when its parameters reference an enclosing non-template class.
251+
Fixes (`#71595 <https://github.com/llvm/llvm-project/issues/71595>`_)
252+
- Fix the name of the ifunc symbol emitted for multiversion functions declared with the
253+
``target_clones`` attribute. This addresses a linker error that would otherwise occur
254+
when these functions are referenced from other TUs.
255+
- Fixes compile error that double colon operator cannot resolve macro with parentheses.
256+
Fixes (`#64467 <https://github.com/llvm/llvm-project/issues/64467>`_)
257+
- Clang's ``-Wchar-subscripts`` no longer warns on chars whose values are known non-negative constants.
258+
Fixes (`#18763 <https://github.com/llvm/llvm-project/issues/18763>`_)
259+
- Fix crash due to incorrectly allowing conversion functions in copy elision.
260+
Fixes (`#39319 <https://github.com/llvm/llvm-project/issues/39319>`_) and
261+
(`#60182 <https://github.com/llvm/llvm-project/issues/60182>`_) and
262+
(`#62157 <https://github.com/llvm/llvm-project/issues/62157>`_) and
263+
(`#64885 <https://github.com/llvm/llvm-project/issues/64885>`_) and
264+
(`#65568 <https://github.com/llvm/llvm-project/issues/65568>`_)
265+
- Fix an issue where clang doesn't respect detault template arguments that
266+
are added in a later redeclaration for CTAD.
267+
Fixes (`#69987 <https://github.com/llvm/llvm-project/issues/69987>`_)
268+
- Fix an issue where CTAD fails for explicit type conversion.
269+
Fixes (`#64347 <https://github.com/llvm/llvm-project/issues/64347>`_)
270+
- Fix crash when using C++ only tokens like ``::`` in C compiler clang.
271+
Fixes (`#73559 <https://github.com/llvm/llvm-project/issues/73559>`_)
272+
- Clang now accepts recursive non-dependent calls to functions with deduced
273+
return type.
274+
Fixes (`#71015 <https://github.com/llvm/llvm-project/issues/71015>`_)
275+
- Fix assertion failure when initializing union containing struct with
276+
flexible array member using empty initializer list.
277+
Fixes (`#77085 <https://github.com/llvm/llvm-project/issues/77085>`_)
278+
- Fix assertion crash due to failed scope restoring caused by too-early VarDecl
279+
invalidation by invalid initializer Expr.
280+
Fixes (`#30908 <https://github.com/llvm/llvm-project/issues/30908>`_)
281+
- Clang now emits correct source location for code-coverage regions in `if constexpr`
282+
and `if consteval` branches.
283+
Fixes (`#54419 <https://github.com/llvm/llvm-project/issues/54419>`_)
284+
- Fix assertion failure when declaring a template friend function with
285+
a constrained parameter in a template class that declares a class method
286+
or lambda at different depth.
287+
Fixes (`#75426 <https://github.com/llvm/llvm-project/issues/75426>`_)
288+
- Fix an issue where clang cannot find conversion function with template
289+
parameter when instantiation of template class.
290+
Fixes (`#77583 <https://github.com/llvm/llvm-project/issues/77583>`_)
291+
- Fix an issue where CTAD fails for function-type/array-type arguments.
292+
Fixes (`#51710 <https://github.com/llvm/llvm-project/issues/51710>`_)
293+
- Fix crashes when using the binding decl from an invalid structured binding.
294+
Fixes (`#67495 <https://github.com/llvm/llvm-project/issues/67495>`_) and
295+
(`#72198 <https://github.com/llvm/llvm-project/issues/72198>`_)
296+
- Fix assertion failure when call noreturn-attribute function with musttail
297+
attribute.
298+
Fixes (`#76631 <https://github.com/llvm/llvm-project/issues/76631>`_)
299+
- The MS ``__noop`` builtin without an argument list is now accepted
300+
in the placement-args of new-expressions, matching MSVC's behaviour.
301+
- Fix an issue that caused MS ``__decspec(property)`` accesses as well as
302+
Objective-C++ property accesses to not be converted to a function call
303+
to the getter in the placement-args of new-expressions.
304+
Fixes (`#65053 <https://github.com/llvm/llvm-project/issues/65053>`_)
305+
- Fix an issue with missing symbol definitions when the first coroutine
306+
statement appears in a discarded ``if constexpr`` branch.
307+
Fixes (`#78290 <https://github.com/llvm/llvm-project/issues/78290>`_)
308+
- Fix crash when using lifetimebound attribute in function with trailing return.
309+
Fixes (`#73619 <https://github.com/llvm/llvm-project/issues/73619>`_)
310+
>>>>>>> 0e74e6cc4d33 ([Clang][Sema] fix crash of attribute transform)
106311

107312
Bug Fixes to Compiler Builtins
108313
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/TypeLoc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,10 @@ class AttributedTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
884884
return getInnerTypeLoc();
885885
}
886886

887+
TypeLoc getEquivalentTypeLoc() const {
888+
return TypeLoc(getTypePtr()->getEquivalentType(), getNonLocalData());
889+
}
890+
887891
/// The type attribute.
888892
const Attr *getAttr() const {
889893
return getLocalData()->TypeAttr;

clang/lib/Sema/TreeTransform.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6131,7 +6131,9 @@ QualType TreeTransform<Derived>::TransformFunctionProtoType(
61316131
// "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
61326132
// and the end of the function-definition, member-declarator, or
61336133
// declarator.
6134-
Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
6134+
auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.getCurLexicalContext());
6135+
Sema::CXXThisScopeRAII ThisScope(
6136+
SemaRef, !ThisContext && RD ? RD : ThisContext, ThisTypeQuals);
61356137

61366138
ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
61376139
if (ResultType.isNull())
@@ -7088,10 +7090,10 @@ QualType TreeTransform<Derived>::TransformAttributedType(
70887090
// FIXME: dependent operand expressions?
70897091
if (getDerived().AlwaysRebuild() ||
70907092
modifiedType != oldType->getModifiedType()) {
7091-
// TODO: this is really lame; we should really be rebuilding the
7092-
// equivalent type from first principles.
7093-
QualType equivalentType
7094-
= getDerived().TransformType(oldType->getEquivalentType());
7093+
TypeLocBuilder AuxiliaryTLB;
7094+
AuxiliaryTLB.reserve(TL.getFullDataSize());
7095+
QualType equivalentType =
7096+
getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
70957097
if (equivalentType.isNull())
70967098
return QualType();
70977099

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clang_cc1 %s -verify -fsyntax-only
2+
3+
// expected-no-diagnostics
4+
5+
template<typename T>
6+
struct Bar {
7+
int* data;
8+
9+
auto operator[](const int index) const [[clang::lifetimebound]] -> decltype(data[index]) {
10+
return data[index];
11+
}
12+
};
13+
14+
int main() {
15+
Bar<int> b;
16+
(void)b[2];
17+
}

0 commit comments

Comments
 (0)