This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG55d3b79d159b: [clang] add APValue type check in `TryPrintAsStringLiteral` (authored by inclyc).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D131466/new/ https://reviews.llvm.org/D131466 Files: clang/lib/AST/APValue.cpp clang/test/SemaCXX/try-print-as-string-literal-type-check.cpp Index: clang/test/SemaCXX/try-print-as-string-literal-type-check.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/try-print-as-string-literal-type-check.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 %s -std=c++20 -fsyntax-only -verify +// expected-no-diagnostics + +// Reported by: https://github.com/llvm/llvm-project/issues/57013 +// The following code should not crash clang +struct X { + char arr[2]; + constexpr X() {} + constexpr void modify() { + arr[0] = 0; + } +}; +constexpr X f(X t) { + t.modify(); + return t; +} +auto x = f(X()); Index: clang/lib/AST/APValue.cpp =================================================================== --- clang/lib/AST/APValue.cpp +++ clang/lib/AST/APValue.cpp @@ -637,10 +637,10 @@ return false; // Nothing we can do about a sequence that is not null-terminated - if (!Inits.back().getInt().isZero()) + if (!Inits.back().isInt() || !Inits.back().getInt().isZero()) return false; - else - Inits = Inits.drop_back(); + + Inits = Inits.drop_back(); llvm::SmallString<40> Buf; Buf.push_back('"'); @@ -655,6 +655,8 @@ } for (auto &Val : Inits) { + if (!Val.isInt()) + return false; int64_t Char64 = Val.getInt().getExtValue(); if (!isASCII(Char64)) return false; // Bye bye, see you in integers.
Index: clang/test/SemaCXX/try-print-as-string-literal-type-check.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/try-print-as-string-literal-type-check.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 %s -std=c++20 -fsyntax-only -verify +// expected-no-diagnostics + +// Reported by: https://github.com/llvm/llvm-project/issues/57013 +// The following code should not crash clang +struct X { + char arr[2]; + constexpr X() {} + constexpr void modify() { + arr[0] = 0; + } +}; +constexpr X f(X t) { + t.modify(); + return t; +} +auto x = f(X()); Index: clang/lib/AST/APValue.cpp =================================================================== --- clang/lib/AST/APValue.cpp +++ clang/lib/AST/APValue.cpp @@ -637,10 +637,10 @@ return false; // Nothing we can do about a sequence that is not null-terminated - if (!Inits.back().getInt().isZero()) + if (!Inits.back().isInt() || !Inits.back().getInt().isZero()) return false; - else - Inits = Inits.drop_back(); + + Inits = Inits.drop_back(); llvm::SmallString<40> Buf; Buf.push_back('"'); @@ -655,6 +655,8 @@ } for (auto &Val : Inits) { + if (!Val.isInt()) + return false; int64_t Char64 = Val.getInt().getExtValue(); if (!isASCII(Char64)) return false; // Bye bye, see you in integers.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits