diff options
author | Timm Baeder <tbaeder@redhat.com> | 2024-08-31 06:24:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-31 06:24:36 +0200 |
commit | 360e4abfc8c7298283041e8f5a07f1829a888d18 (patch) | |
tree | b202f7502df0fbc2a6cbfc95f3a396786821d071 /clang/lib/AST/ByteCode/Pointer.cpp | |
parent | ef50970204384643acca42ba4c7ca8f14865a0c2 (diff) | |
download | llvm-360e4abfc8c7298283041e8f5a07f1829a888d18.zip llvm-360e4abfc8c7298283041e8f5a07f1829a888d18.tar.gz llvm-360e4abfc8c7298283041e8f5a07f1829a888d18.tar.bz2 |
[clang][bytecode] Diagnose comparisons with literals (#106734)
This requires adding a new opcode for PointerToBoolean casts, since we
otherwise emit too many diagnostics. But that fixes an older problem
when casting weak pointers to bool.
Diffstat (limited to 'clang/lib/AST/ByteCode/Pointer.cpp')
-rw-r--r-- | clang/lib/AST/ByteCode/Pointer.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp index 5b9e837..9eaf0db 100644 --- a/clang/lib/AST/ByteCode/Pointer.cpp +++ b/clang/lib/AST/ByteCode/Pointer.cpp @@ -463,6 +463,17 @@ bool Pointer::hasSameArray(const Pointer &A, const Pointer &B) { A.getFieldDesc()->IsArray; } +bool Pointer::pointsToLiteral() const { + if (isZero() || !isBlockPointer()) + return false; + + const Expr *E = block()->getDescriptor()->asExpr(); + if (block()->isDynamic()) + return false; + + return E && !isa<MaterializeTemporaryExpr, StringLiteral>(E); +} + std::optional<APValue> Pointer::toRValue(const Context &Ctx, QualType ResultType) const { const ASTContext &ASTCtx = Ctx.getASTContext(); |