[llvm-branch-commits] [flang] 352b872 - Add list input test to GTest suite
Author: Asher Mancinelli Date: 2021-03-30T11:16:23-07:00 New Revision: 352b872f8f717a98328eb48b57f0a4d83c686d9f URL: https://github.com/llvm/llvm-project/commit/352b872f8f717a98328eb48b57f0a4d83c686d9f DIFF: https://github.com/llvm/llvm-project/commit/352b872f8f717a98328eb48b57f0a4d83c686d9f.diff LOG: Add list input test to GTest suite Added: flang/unittests/RuntimeGTest/ListInputTest.cpp Modified: flang/unittests/RuntimeGTest/CMakeLists.txt Removed: diff --git a/flang/unittests/RuntimeGTest/CMakeLists.txt b/flang/unittests/RuntimeGTest/CMakeLists.txt index d4ad6b2e15201..3e48b67f5a098 100644 --- a/flang/unittests/RuntimeGTest/CMakeLists.txt +++ b/flang/unittests/RuntimeGTest/CMakeLists.txt @@ -5,6 +5,7 @@ add_flang_unittest(FlangRuntimeTests NumericalFormatTest.cpp RuntimeCrashTest.cpp CrashHandlerFixture.cpp + ListInputTest.cpp ) target_link_libraries(FlangRuntimeTests diff --git a/flang/unittests/RuntimeGTest/ListInputTest.cpp b/flang/unittests/RuntimeGTest/ListInputTest.cpp new file mode 100644 index 0..f1f62197ae07e --- /dev/null +++ b/flang/unittests/RuntimeGTest/ListInputTest.cpp @@ -0,0 +1,76 @@ +//===-- flang/unittests/RuntimeGTest/ListInputTest.cpp --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "CrashHandlerFixture.h" +#include "../../runtime/descriptor.h" +#include "../../runtime/io-api.h" +#include "../../runtime/io-error.h" + +using namespace Fortran::runtime; +using namespace Fortran::runtime::io; + +// Pads characters with whitespace when needed +void SetCharacter(char *to, std::size_t n, const char *from) { + auto len{std::strlen(from)}; + std::memcpy(to, from, std::min(len, n)); + if (len < n) { +std::memset(to + len, ' ', n - len); + } +} + +struct InputTest : CrashHandlerFixture {}; + +TEST(InputTest, TestListInput) { + static constexpr int numBuffers{4}; + static constexpr int maxBufferLength{32}; + static char buffer[numBuffers][maxBufferLength]; + int j{0}; + for (const char *p : {"1 2 2*3 ,", ",6,,8,1*", + "2*'abcdefghijklmnopqrstuvwxyzABC", "DEFGHIJKLMNOPQRSTUVWXYZ'"}) { +SetCharacter(buffer[j++], maxBufferLength, p); + } + + static StaticDescriptor<1> staticDescriptor; + static Descriptor &whole{staticDescriptor.descriptor()}; + static SubscriptValue extent[]{numBuffers}; + whole.Establish(TypeCode{CFI_type_char}, maxBufferLength, &buffer, 1, extent, + CFI_attribute_pointer); + whole.Dump(); + whole.Check(); + + static auto cookie{IONAME(BeginInternalArrayListInput)(whole)}; + static constexpr int listInputLength{9}; + static std::int64_t n[listInputLength]{-1, -2, -3, -4, 5, -6, 7, -8, 9}; + static const std::int64_t want[listInputLength]{1, 2, 3, 3, 5, 6, 7, 8, 9}; + for (j = 0; j < listInputLength; ++j) { +IONAME(InputInteger)(cookie, n[j]); + } + + static constexpr int numInputBuffers{2}; + static constexpr int inputBufferLength{54}; + static char inputBuffers[numInputBuffers][inputBufferLength]{}; + IONAME(InputAscii)(cookie, inputBuffers[0], inputBufferLength - 1); + IONAME(InputAscii)(cookie, inputBuffers[1], inputBufferLength - 1); + + static const auto status{IONAME(EndIoStatement)(cookie)}; + ASSERT_EQ(status, 0) << "list-directed input failed, status " + << static_cast(status) << '\n'; + + for (j = 0; j < listInputLength; ++j) { +ASSERT_EQ(n[j], want[j]) +<< "wanted n[" << j << "]==" << want[j] << ", got " << n[j] << '\n'; + } + + for (j = 0; j < numInputBuffers; ++j) { +ASSERT_EQ(std::strcmp(inputBuffers[j], + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "), +0) +<< "wanted asc[" << j << "]=alphabets, got '" << inputBuffers[j] << "'\n"; + } +} + ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] ee822a6 - Remove legacy list-input test
Author: Asher Mancinelli Date: 2021-03-30T11:25:42-07:00 New Revision: ee822a6bda40f6b17ba7b4c6d414827c665c9480 URL: https://github.com/llvm/llvm-project/commit/ee822a6bda40f6b17ba7b4c6d414827c665c9480 DIFF: https://github.com/llvm/llvm-project/commit/ee822a6bda40f6b17ba7b4c6d414827c665c9480.diff LOG: Remove legacy list-input test Added: Modified: flang/unittests/Runtime/CMakeLists.txt Removed: flang/unittests/Runtime/list-input.cpp diff --git a/flang/unittests/Runtime/CMakeLists.txt b/flang/unittests/Runtime/CMakeLists.txt index cc7ac72771839..03998fa55d143 100644 --- a/flang/unittests/Runtime/CMakeLists.txt +++ b/flang/unittests/Runtime/CMakeLists.txt @@ -37,11 +37,6 @@ add_flang_nongtest_unittest(external-io FortranRuntime ) -add_flang_nongtest_unittest(list-input - RuntimeTesting - FortranRuntime -) - add_flang_nongtest_unittest(buffer RuntimeTesting FortranRuntime diff --git a/flang/unittests/Runtime/list-input.cpp b/flang/unittests/Runtime/list-input.cpp deleted file mode 100644 index 9ec77080203a2..0 --- a/flang/unittests/Runtime/list-input.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// Basic sanity tests for list-directed input - -#include "testing.h" -#include "../../runtime/descriptor.h" -#include "../../runtime/io-api.h" -#include "../../runtime/io-error.h" -#include -#include - -using namespace Fortran::runtime; -using namespace Fortran::runtime::io; - -int main() { - StartTests(); - - char buffer[4][32]; - int j{0}; - for (const char *p : {"1 2 2*3 ,", ",6,,8,1*", - "2*'abcdefghijklmnopqrstuvwxyzABC", "DEFGHIJKLMNOPQRSTUVWXYZ'"}) { -SetCharacter(buffer[j++], sizeof buffer[0], p); - } - for (; j < 4; ++j) { -SetCharacter(buffer[j], sizeof buffer[0], ""); - } - - StaticDescriptor<1> staticDescriptor; - Descriptor &whole{staticDescriptor.descriptor()}; - SubscriptValue extent[]{4}; - whole.Establish(TypeCode{CFI_type_char}, sizeof buffer[0], &buffer, 1, extent, - CFI_attribute_pointer); - whole.Dump(); - whole.Check(); - - try { -auto cookie{IONAME(BeginInternalArrayListInput)(whole)}; -std::int64_t n[9]{-1, -2, -3, -4, 5, -6, 7, -8, 9}; -std::int64_t want[9]{1, 2, 3, 3, 5, 6, 7, 8, 9}; -for (j = 0; j < 9; ++j) { - IONAME(InputInteger)(cookie, n[j]); -} -char asc[2][54]{}; -IONAME(InputAscii)(cookie, asc[0], sizeof asc[0] - 1); -IONAME(InputAscii)(cookie, asc[1], sizeof asc[1] - 1); -if (auto status{IONAME(EndIoStatement)(cookie)}) { - Fail() << "list-directed input failed, status " - << static_cast(status) << '\n'; -} else { - for (j = 0; j < 9; ++j) { -if (n[j] != want[j]) { - Fail() << "wanted n[" << j << "]==" << want[j] << ", got " << n[j] - << '\n'; -} - } - for (j = 0; j < 2; ++j) { -if (std::strcmp(asc[j], -"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ") != 0) { - Fail() << "wanted asc[" << j << "]=alphabets, got '" << asc[j] - << "'\n"; -} - } -} - } catch (const std::string &crash) { -Fail() << "crash: " << crash << '\n'; - } - - return EndTests(); -} ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] bc26c5f - Clang-format list input test
Author: Asher Mancinelli Date: 2021-03-30T11:31:39-07:00 New Revision: bc26c5fb2a5601971691a69c6d8bf9f7b5cd7326 URL: https://github.com/llvm/llvm-project/commit/bc26c5fb2a5601971691a69c6d8bf9f7b5cd7326 DIFF: https://github.com/llvm/llvm-project/commit/bc26c5fb2a5601971691a69c6d8bf9f7b5cd7326.diff LOG: Clang-format list input test Added: Modified: flang/unittests/RuntimeGTest/ListInputTest.cpp Removed: diff --git a/flang/unittests/RuntimeGTest/ListInputTest.cpp b/flang/unittests/RuntimeGTest/ListInputTest.cpp index f1f62197ae07e..5d693d77f2114 100644 --- a/flang/unittests/RuntimeGTest/ListInputTest.cpp +++ b/flang/unittests/RuntimeGTest/ListInputTest.cpp @@ -59,7 +59,7 @@ TEST(InputTest, TestListInput) { static const auto status{IONAME(EndIoStatement)(cookie)}; ASSERT_EQ(status, 0) << "list-directed input failed, status " - << static_cast(status) << '\n'; + << static_cast(status) << '\n'; for (j = 0; j < listInputLength; ++j) { ASSERT_EQ(n[j], want[j]) @@ -70,7 +70,7 @@ TEST(InputTest, TestListInput) { ASSERT_EQ(std::strcmp(inputBuffers[j], "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "), 0) -<< "wanted asc[" << j << "]=alphabets, got '" << inputBuffers[j] << "'\n"; +<< "wanted asc[" << j << "]=alphabets, got '" << inputBuffers[j] +<< "'\n"; } } - ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] 679fe69 - Apply first pass at diag handler structure
Author: Asher Mancinelli Date: 2021-04-05T09:00:33-07:00 New Revision: 679fe69e92f192ef8d3b014dcf7e1624e16c9c77 URL: https://github.com/llvm/llvm-project/commit/679fe69e92f192ef8d3b014dcf7e1624e16c9c77 DIFF: https://github.com/llvm/llvm-project/commit/679fe69e92f192ef8d3b014dcf7e1624e16c9c77.diff LOG: Apply first pass at diag handler structure Added: flang/include/flang/Common/colors.h flang/include/flang/Parser/diagnostics-engine.h Modified: flang/include/flang/Parser/message.h flang/lib/Parser/message.cpp Removed: diff --git a/flang/include/flang/Common/colors.h b/flang/include/flang/Common/colors.h new file mode 100644 index 0..feb259c22c674 --- /dev/null +++ b/flang/include/flang/Common/colors.h @@ -0,0 +1,34 @@ +//===-- include/flang/Parser/colors.h ---*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Defines colors used for diagnostics. +// +//===--===// + +#ifndef FORTRAN_PARSER_COLORS_H_ +#define FORTRAN_PARSER_COLORS_H_ + +#include "llvm/Support/raw_ostream.h" + +namespace Fortran::common { + +static constexpr enum llvm::raw_ostream::Colors noteColor = +llvm::raw_ostream::BLACK; +static constexpr enum llvm::raw_ostream::Colors remarkColor = +llvm::raw_ostream::BLUE; +static constexpr enum llvm::raw_ostream::Colors warningColor = +llvm::raw_ostream::MAGENTA; +static constexpr enum llvm::raw_ostream::Colors errorColor = llvm::raw_ostream::RED; +static constexpr enum llvm::raw_ostream::Colors fatalColor = llvm::raw_ostream::RED; +// Used for changing only the bold attribute. +static constexpr enum llvm::raw_ostream::Colors savedColor = +llvm::raw_ostream::SAVEDCOLOR; + +} // namespace Fortran::common + +#endif \ No newline at end of file diff --git a/flang/include/flang/Parser/diagnostics-engine.h b/flang/include/flang/Parser/diagnostics-engine.h new file mode 100644 index 0..beb03d77aeeb0 --- /dev/null +++ b/flang/include/flang/Parser/diagnostics-engine.h @@ -0,0 +1,20 @@ +//===-- include/flang/Parser/characters.h ---*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef FORTRAN_PARSER_CHARACTERS_H_ +#define FORTRAN_PARSER_CHARACTERS_H_ + +namespace Fortran::parser { + +class DiagnosticsEngine { + +}; + +} // namespace Fortran::parser + +#endif \ No newline at end of file diff --git a/flang/include/flang/Parser/message.h b/flang/include/flang/Parser/message.h index 13f30879dc4fb..fbba0b922e018 100644 --- a/flang/include/flang/Parser/message.h +++ b/flang/include/flang/Parser/message.h @@ -29,34 +29,46 @@ namespace Fortran::parser { +enum class DiagnosticLevel { + Note=0, + Remark, + Warning, + Error, + Fatal, +}; + // Use "..."_err_en_US and "..."_en_US literals to define the static // text and fatality of a message. class MessageFixedText { public: constexpr MessageFixedText( - const char str[], std::size_t n, bool isFatal = false) - : text_{str, n}, isFatal_{isFatal} {} + const char str[], std::size_t n, DiagnosticLevel diagnosticLevel = DiagnosticLevel::Remark) + : text_{str, n}, diagnosticLevel_{diagnosticLevel} {} + constexpr MessageFixedText( + const char str[], std::size_t n, bool isFatal) + : text_{str, n}, diagnosticLevel_{isFatal ? DiagnosticLevel::Fatal : DiagnosticLevel::Remark} {} constexpr MessageFixedText(const MessageFixedText &) = default; constexpr MessageFixedText(MessageFixedText &&) = default; constexpr MessageFixedText &operator=(const MessageFixedText &) = default; constexpr MessageFixedText &operator=(MessageFixedText &&) = default; CharBlock text() const { return text_; } - bool isFatal() const { return isFatal_; } + bool isFatal() const { return diagnosticLevel_ == DiagnosticLevel::Fatal; } + DiagnosticLevel GetDiagnosticLevel() const { return diagnosticLevel_; } private: CharBlock text_; - bool isFatal_{false}; + DiagnosticLevel diagnosticLevel_{DiagnosticLevel::Remark}; }; inline namespace literals { constexpr MessageFixedText operator""_en_US(const char str[], std::size_t n) { - return MessageFixedText{str, n, false /* not fatal */}; + return MessageFixedText{str, n, DiagnosticLevel::Remark}; } constexpr MessageFixedText operator""_err_en_US( const char str[], std::size_t n)
[llvm-branch-commits] [clang] e858189 - [analyzer] DynamicSize: Store the dynamic size
Author: Charusso Date: 2021-04-05T18:42:47+02:00 New Revision: e858189976d900938e75084cbbe86249e204fbba URL: https://github.com/llvm/llvm-project/commit/e858189976d900938e75084cbbe86249e204fbba DIFF: https://github.com/llvm/llvm-project/commit/e858189976d900938e75084cbbe86249e204fbba.diff LOG: [analyzer] DynamicSize: Store the dynamic size This patch introduces a way to store the size. Reviewed By: NoQ Differential Revision: https://reviews.llvm.org/D69726 Added: Modified: clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp clang/lib/StaticAnalyzer/Core/DynamicSize.cpp clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp clang/lib/StaticAnalyzer/Core/MemRegion.cpp clang/test/Analysis/explain-svals.cpp Removed: diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h index 398f9b6ac33a..bad6a19cb9ff 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h @@ -22,15 +22,21 @@ namespace clang { namespace ento { -/// Get the stored dynamic size for the region \p MR. +/// \returns The stored dynamic size for the region \p MR. DefinedOrUnknownSVal getDynamicSize(ProgramStateRef State, const MemRegion *MR, SValBuilder &SVB); -/// Get the stored element count of the region \p MR. +/// \returns The element size of the type \p Ty. +DefinedOrUnknownSVal getElementSize(QualType Ty, SValBuilder &SVB); + +/// \returns The stored element count of the region \p MR. DefinedOrUnknownSVal getDynamicElementCount(ProgramStateRef State, const MemRegion *MR, -SValBuilder &SVB, -QualType ElementTy); +SValBuilder &SVB, QualType Ty); + +/// Set the dynamic size \p Size of the region \p MR. +ProgramStateRef setDynamicSize(ProgramStateRef State, const MemRegion *MR, + DefinedOrUnknownSVal Size, SValBuilder &SVB); /// Get the dynamic size for a symbolic value that represents a buffer. If /// there is an offsetting to the underlying buffer we consider that too. @@ -45,7 +51,7 @@ DefinedOrUnknownSVal getDynamicElementCount(ProgramStateRef State, /// /// char *bufptr; /// (bufptr) // size is unknown -SVal getDynamicSizeWithOffset(ProgramStateRef State, const SVal &BufV); +SVal getDynamicSizeWithOffset(ProgramStateRef State, SVal BufV); } // namespace ento } // namespace clang diff --git a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp index 233ce57c3ac9..31f9b14f7eeb 100644 --- a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp @@ -92,12 +92,8 @@ bool BuiltinFunctionChecker::evalCall(const CallEvent &Call, if (Size.isUndef()) return true; // Return true to model purity. -SValBuilder& svalBuilder = C.getSValBuilder(); -DefinedOrUnknownSVal DynSize = getDynamicSize(state, R, svalBuilder); -DefinedOrUnknownSVal DynSizeMatchesSizeArg = -svalBuilder.evalEQ(state, DynSize, Size.castAs()); -state = state->assume(DynSizeMatchesSizeArg, true); -assert(state && "The region should not have any previous constraints"); +state = setDynamicSize(state, R, Size.castAs(), + C.getSValBuilder()); C.addTransition(state->BindExpr(CE, LCtx, loc::MemRegionVal(R))); return true; diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index f117d5505ecb..7eafdaa97bb4 100644 --- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -509,10 +509,6 @@ class MallocChecker ProgramStateRef State, AllocationFamily Family); - LLVM_NODISCARD - static ProgramStateRef addExtentSize(CheckerContext &C, const CXXNewExpr *NE, - ProgramStateRef State, SVal Target); - // Check if this malloc() for special flags. At present that means M_ZERO or // __GFP_ZERO (in which case, treat it like calloc). LLVM_NODISCARD @@ -1424,7 +1420,6 @@ MallocChecker::processNewAllocation(const CXXAllocatorCall &Call, // existing binding. SVal Target = Call.getObjectUnderConstruction(); State = MallocUpdateRefState(C, NE, State