diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 7a5bd4dfc0bed..2436c844b169d 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -2038,7 +2038,12 @@ bool Compiler::visitCallArgs(ArrayRef Args, const FunctionDecl *FuncDecl, bool Activate) { assert(VarScope->getKind() == ScopeKind::Call); - llvm::BitVector NonNullArgs = collectNonNullArgs(FuncDecl, Args); + bool HasNonNullAttr = false; + llvm::BitVector NonNullArgs; + if (FuncDecl && FuncDecl->hasAttr()) { + HasNonNullAttr = true; + NonNullArgs = collectNonNullArgs(FuncDecl, Args); + } unsigned ArgIndex = 0; for (const Expr *Arg : Args) { @@ -2064,7 +2069,7 @@ bool Compiler::visitCallArgs(ArrayRef Args, return false; } - if (FuncDecl && NonNullArgs[ArgIndex]) { + if (HasNonNullAttr && NonNullArgs[ArgIndex]) { PrimType ArgT = classify(Arg).value_or(PT_Ptr); if (ArgT == PT_Ptr) { if (!this->emitCheckNonNullArg(ArgT, Arg)) diff --git a/clang/lib/AST/ByteCode/InterpShared.cpp b/clang/lib/AST/ByteCode/InterpShared.cpp index 1e94dc19d03c1..e01b32bc63a2a 100644 --- a/clang/lib/AST/ByteCode/InterpShared.cpp +++ b/clang/lib/AST/ByteCode/InterpShared.cpp @@ -16,23 +16,23 @@ namespace interp { llvm::BitVector collectNonNullArgs(const FunctionDecl *F, ArrayRef Args) { llvm::BitVector NonNullArgs; - if (!F) - return NonNullArgs; assert(F); + assert(F->hasAttr()); NonNullArgs.resize(Args.size()); for (const auto *Attr : F->specific_attrs()) { if (!Attr->args_size()) { NonNullArgs.set(); break; - } else - for (auto Idx : Attr->args()) { - unsigned ASTIdx = Idx.getASTIndex(); - if (ASTIdx >= Args.size()) - continue; - NonNullArgs[ASTIdx] = true; - } + } + + for (auto Idx : Attr->args()) { + unsigned ASTIdx = Idx.getASTIndex(); + if (ASTIdx >= Args.size()) + continue; + NonNullArgs[ASTIdx] = true; + } } return NonNullArgs; diff --git a/clang/test/AST/ByteCode/nullable.cpp b/clang/test/AST/ByteCode/nullable.cpp index 3bc2595fb8f00..9e79fc7dd5a39 100644 --- a/clang/test/AST/ByteCode/nullable.cpp +++ b/clang/test/AST/ByteCode/nullable.cpp @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=expected,both %s -// RUN: %clang_cc1 -verify=ref,both %s +// RUN: %clang_cc1 -verify=expected,both %s -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 -verify=ref,both %s constexpr int dummy = 1;