diff options
author | Timm Bäder <tbaeder@redhat.com> | 2023-08-10 09:16:10 +0200 |
---|---|---|
committer | Timm Bäder <tbaeder@redhat.com> | 2023-08-10 09:17:07 +0200 |
commit | b56ab41d54e6beb17c06eefbfcf306af2c4d8107 (patch) | |
tree | 92e40d965a171705bcbdf0998cd9ca425d2c808c | |
parent | ac2af811a0b864df0089b454b61d484bfc1ad108 (diff) | |
download | llvm-b56ab41d54e6beb17c06eefbfcf306af2c4d8107.zip llvm-b56ab41d54e6beb17c06eefbfcf306af2c4d8107.tar.gz llvm-b56ab41d54e6beb17c06eefbfcf306af2c4d8107.tar.bz2 |
Revert "[clang][Interp] Basic support for bit fields"
This reverts commit 8065b1cc133c9e4b6900d5c11220617180706b94.
This breaks builders. I forgot this depends
on https://reviews.llvm.org/D155548
-rw-r--r-- | clang/lib/AST/Interp/ByteCodeExprGen.cpp | 15 | ||||
-rw-r--r-- | clang/lib/AST/Interp/ByteCodeStmtGen.cpp | 9 | ||||
-rw-r--r-- | clang/lib/AST/Interp/Interp.h | 14 | ||||
-rw-r--r-- | clang/lib/AST/Interp/Record.h | 1 | ||||
-rw-r--r-- | clang/test/AST/Interp/bitfields.cpp | 47 |
5 files changed, 13 insertions, 73 deletions
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 4c0b599..8a756e4f 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -305,10 +305,8 @@ bool ByteCodeExprGen<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) { return Discard(this->emitDiv(*T, BO)); case BO_Assign: if (DiscardResult) - return LHS->refersToBitField() ? this->emitStoreBitFieldPop(*T, BO) - : this->emitStorePop(*T, BO); - return LHS->refersToBitField() ? this->emitStoreBitField(*T, BO) - : this->emitStore(*T, BO); + return this->emitStorePop(*T, BO); + return this->emitStore(*T, BO); case BO_And: return Discard(this->emitBitAnd(*T, BO)); case BO_Or: @@ -1592,13 +1590,8 @@ bool ByteCodeExprGen<Emitter>::visitRecordInitializer(const Expr *Initializer) { if (!this->visit(Init)) return false; - if (FieldToInit->isBitField()) { - if (!this->emitInitBitField(*T, FieldToInit, Initializer)) - return false; - } else { - if (!this->emitInitField(*T, FieldToInit->Offset, Initializer)) - return false; - } + if (!this->emitInitField(*T, FieldToInit->Offset, Initializer)) + return false; if (!this->emitPopPtr(Initializer)) return false; diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp index cce7067..e54805c 100644 --- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp @@ -169,13 +169,8 @@ bool ByteCodeStmtGen<Emitter>::visitFunc(const FunctionDecl *F) { if (!this->visit(InitExpr)) return false; - if (F->isBitField()) { - if (!this->emitInitThisBitField(*T, F, InitExpr)) - return false; - } else { - if (!this->emitInitThisField(*T, F->Offset, InitExpr)) - return false; - } + if (!this->emitInitThisField(*T, F->Offset, InitExpr)) + return false; } else { // Non-primitive case. Get a pointer to the field-to-initialize // on the stack and call visitInitialzer() for it. diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index f1fb4e3..c278144 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -1007,7 +1007,6 @@ bool InitThisField(InterpState &S, CodePtr OpPC, uint32_t I) { template <PrimType Name, class T = typename PrimConv<Name>::T> bool InitThisBitField(InterpState &S, CodePtr OpPC, const Record::Field *F) { - assert(F->isBitField()); if (S.checkingPotentialConstantExpression()) return false; const Pointer &This = S.Current->getThis(); @@ -1049,9 +1048,8 @@ bool InitField(InterpState &S, CodePtr OpPC, uint32_t I) { template <PrimType Name, class T = typename PrimConv<Name>::T> bool InitBitField(InterpState &S, CodePtr OpPC, const Record::Field *F) { - assert(F->isBitField()); const T &Value = S.Stk.pop<T>(); - const Pointer &Field = S.Stk.peek<Pointer>().atField(F->Offset); + const Pointer &Field = S.Stk.pop<Pointer>().atField(F->Offset); Field.deref<T>() = Value.truncate(F->Decl->getBitWidthValue(S.getCtx())); Field.activate(); Field.initialize(); @@ -1249,10 +1247,11 @@ bool StoreBitField(InterpState &S, CodePtr OpPC) { return false; if (!Ptr.isRoot()) Ptr.initialize(); - if (const auto *FD = Ptr.getField()) + if (auto *FD = Ptr.getField()) { Ptr.deref<T>() = Value.truncate(FD->getBitWidthValue(S.getCtx())); - else + } else { Ptr.deref<T>() = Value; + } return true; } @@ -1264,10 +1263,11 @@ bool StoreBitFieldPop(InterpState &S, CodePtr OpPC) { return false; if (!Ptr.isRoot()) Ptr.initialize(); - if (const auto *FD = Ptr.getField()) + if (auto *FD = Ptr.getField()) { Ptr.deref<T>() = Value.truncate(FD->getBitWidthValue(S.getCtx())); - else + } else { Ptr.deref<T>() = Value; + } return true; } diff --git a/clang/lib/AST/Interp/Record.h b/clang/lib/AST/Interp/Record.h index 5219734f..940b4c9 100644 --- a/clang/lib/AST/Interp/Record.h +++ b/clang/lib/AST/Interp/Record.h @@ -29,7 +29,6 @@ public: const FieldDecl *Decl; unsigned Offset; Descriptor *Desc; - bool isBitField() const { return Decl->isBitField(); } }; /// Describes a base class. diff --git a/clang/test/AST/Interp/bitfields.cpp b/clang/test/AST/Interp/bitfields.cpp deleted file mode 100644 index e078704..0000000 --- a/clang/test/AST/Interp/bitfields.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -Wno-bitfield-constant-conversion -verify %s -// RUN: %clang_cc1 -verify=ref -Wno-bitfield-constant-conversion %s - -// expected-no-diagnostics -// ref-no-diagnostics - -namespace Basic { - struct A { - unsigned int a : 2; - constexpr A() : a(0) {} - constexpr A(int a) : a(a) {} - }; - - constexpr A a{1}; - static_assert(a.a == 1, ""); - - constexpr A a2{10}; - static_assert(a2.a == 2, ""); - - - constexpr int storeA() { - A a; - a.a = 10; - - return a.a; - } - static_assert(storeA() == 2, ""); - - constexpr int storeA2() { - A a; - return a.a = 10; - } - static_assert(storeA2() == 2, ""); - - // TODO: +=, -=, etc. operators. -} - -namespace Overflow { - struct A {int c:3;}; - - constexpr int f() { - A a1{3}; - return a1.c++; - } - - static_assert(f() == 3, ""); -} |