Skip to content

Commit

Permalink
[Clang][Sema] Do not try to analyze dependent alignment during -Wcast…
Browse files Browse the repository at this point in the history
…-align

Fix #63007

Differential Revision: https://reviews.llvm.org/D151753
  • Loading branch information
serge-sans-paille committed Jun 27, 2023
1 parent d98e44b commit dc6f5c9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ Improvements to Clang's diagnostics
- Clang now diagnoses unexpected tokens after a
``#pragma clang|GCC diagnostic push|pop`` directive.
(`#13920: <https://github.com/llvm/llvm-project/issues/13920>`_)
- Clang now does not try to analyze cast validity on variables with dependent alignment (`#63007: <https://github.com/llvm/llvm-project/issues/63007>`_).

Bug Fixes in This Version
-------------------------
Expand Down
6 changes: 5 additions & 1 deletion clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16351,8 +16351,12 @@ std::optional<std::pair<
if (auto *VD = dyn_cast<VarDecl>(cast<DeclRefExpr>(E)->getDecl())) {
// FIXME: If VD is captured by copy or is an escaping __block variable,
// use the alignment of VD's type.
if (!VD->getType()->isReferenceType())
if (!VD->getType()->isReferenceType()) {
// Dependent alignment cannot be resolved -> bail out.
if (VD->hasDependentAlignment())
break;
return std::make_pair(Ctx.getDeclAlign(VD), CharUnits::Zero());
}
if (VD->hasInit())
return getBaseAlignmentAndOffsetFromLValue(VD->getInit(), Ctx);
}
Expand Down
5 changes: 5 additions & 0 deletions clang/test/SemaCXX/warn-cast-align.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ void test1(void *P) {
c = IntPtr(P);
}

template <class A> void DependentAlign() {
alignas(A) int lut[]{};
(long *)lut; // expected-warning {{cast from 'int *' to 'long *'}}
}

struct __attribute__((aligned(16))) AlignedS {
char m[16];
};
Expand Down

0 comments on commit dc6f5c9

Please sign in to comment.