This is an archive of the discontinued LLVM Phabricator instance.

[AST] Fix recovery-expr crash on invalid aligned attr.
ClosedPublic

Authored by hokein on Apr 14 2020, 12:24 AM.

Details

Summary

crash stack:

lang: tools/clang/include/clang/AST/AttrImpl.inc:1490: unsigned int clang::AlignedAttr::getAlignment(clang::ASTContext &) const: Assertion `!isAlignmentDependent()' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: ./bin/clang -cc1 -std=c++1y -ast-dump -frecovery-ast -fcxx-exceptions /tmp/t4.cpp
1.      /tmp/t4.cpp:3:31: current parser token ';'
 #0 0x0000000002530cff llvm::sys::PrintStackTrace(llvm::raw_ostream&) llvm-project/llvm/lib/Support/Unix/Signals.inc:564:13
 #1 0x000000000252ee30 llvm::sys::RunSignalHandlers() llvm-project/llvm/lib/Support/Signals.cpp:69:18
 #2 0x000000000253126c SignalHandler(int) llvm-project/llvm/lib/Support/Unix/Signals.inc:396:3
 #3 0x00007f86964d0520 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x13520)
 #4 0x00007f8695f9ff61 raise /build/glibc-oCLvUT/glibc-2.29/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007f8695f8b535 abort /build/glibc-oCLvUT/glibc-2.29/stdlib/abort.c:81:7
 #6 0x00007f8695f8b40f _nl_load_domain /build/glibc-oCLvUT/glibc-2.29/intl/loadmsgcat.c:1177:9
 #7 0x00007f8695f98b92 (/lib/x86_64-linux-gnu/libc.so.6+0x32b92)
 #8 0x0000000004503d9f llvm::APInt::getZExtValue() const llvm-project/llvm/include/llvm/ADT/APInt.h:1623:5
 #9 0x0000000004503d9f clang::AlignedAttr::getAlignment(clang::ASTContext&) const llvm-project/build/tools/clang/include/clang/AST/AttrImpl.inc:1492:0

Diff Detail

Event Timeline

hokein created this revision.Apr 14 2020, 12:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2020, 12:24 AM
sammccall added inline comments.Apr 14 2020, 12:41 PM
clang/lib/AST/DeclBase.cpp
400

This doesn't seem great - previously if e.g. codegen ends up needing the alignment of a dependent decl somehow, then an assert will catch that programming error.
Now it'll be silently swallowed. Seems better to check isAlignmentErrorDependent() here (you'd need to add that function) and continue to assert in other dependent cases.

hokein updated this revision to Diff 257638.Apr 15 2020, 2:26 AM
hokein marked an inline comment as done.

Use isAlignmentErrorDependent.

hokein added inline comments.Apr 15 2020, 2:28 AM
clang/lib/AST/DeclBase.cpp
400

ah, right. I think we should probably fix other similar places (where I added FIXMEs). We don't have problems at the moment -- because the recovery-expr is dependent, and they have been bailed out by isAlignmentDependent(). If we start capture the concrete type for recovery-expr, the isAlignmentDependent bailout will fail.

The isAlignmentDependent seems a bit confusing now, what does the dependent mean? if we generalize it, it could mean the attr depends on a template parameter (type, value, instantiation) or an error, in this sense isAlignmentDependent should cover the error-dependent case. I think here it only indicates the type-, value-, instantiation- dependent.

sammccall added inline comments.Apr 15 2020, 2:49 AM
clang/lib/AST/ComputeDependence.cpp
74

maybe just do this unless it causes regressions?

clang/lib/Sema/SemaDecl.cpp
2434 ↗(On Diff #257638)

I actually don't think we should add this FIXME.
Currently error dependence implies dependence. If we break this invariant, there are going to be hundreds of places that check for dependence and need to be updated. We haven't annotated them all with fixmes.

sammccall accepted this revision.Apr 15 2020, 2:50 AM

LG with comments

This revision is now accepted and ready to land.Apr 15 2020, 2:50 AM
hokein updated this revision to Diff 257712.Apr 15 2020, 7:12 AM

address comments.

This revision was automatically updated to reflect the committed changes.