Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DataFormatters] Add formatter for C++17 std::variant
rdar://problem/43691454 Patch by Shafik Yaghmour. Differential Revision: https://reviews.llvm.org/D51520 llvm-svn: 342563
- Loading branch information
Showing
9 changed files
with
458 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
.../lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
LEVEL = ../../../../../make | ||
|
||
CXX_SOURCES := main.cpp | ||
|
||
USE_LIBCPP := 1 | ||
include $(LEVEL)/Makefile.rules | ||
CXXFLAGS += -std=c++17 |
81 changes: 81 additions & 0 deletions
81
...lities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
""" | ||
Test lldb data formatter subsystem. | ||
""" | ||
|
||
from __future__ import print_function | ||
|
||
|
||
import os | ||
import time | ||
import lldb | ||
from lldbsuite.test.decorators import * | ||
from lldbsuite.test.lldbtest import * | ||
from lldbsuite.test import lldbutil | ||
|
||
class LibcxxOptionalDataFormatterTestCase(TestBase): | ||
|
||
mydir = TestBase.compute_mydir(__file__) | ||
|
||
@add_test_categories(["libc++"]) | ||
## We are skipping clang version less that 5.0 since this test requires -std=c++17 | ||
@skipIf(oslist=no_match(["macosx"]), compiler="clang", compiler_version=['<', '5.0']) | ||
## We are skipping gcc version less that 5.1 since this test requires -std=c++17 | ||
@skipIf(compiler="gcc", compiler_version=['<', '5.1']) | ||
|
||
def test_with_run_command(self): | ||
"""Test that that file and class static variables display correctly.""" | ||
self.build() | ||
|
||
(self.target, self.process, _, bkpt) = lldbutil.run_to_source_breakpoint(self, '// break here', | ||
lldb.SBFileSpec("main.cpp", False)) | ||
|
||
self.runCmd( "frame variable has_variant" ) | ||
|
||
output = self.res.GetOutput() | ||
|
||
## The variable has_variant tells us if the test program | ||
## detected we have a sufficient libc++ version to support variant | ||
## false means we do not and therefore should skip the test | ||
if output.find("(bool) has_variant = false") != -1 : | ||
self.skipTest( "std::variant not supported" ) | ||
|
||
lldbutil.continue_to_breakpoint(self.process, bkpt) | ||
|
||
self.expect("frame variable v1", | ||
substrs=['v1 = Active Type = int {', | ||
'Value = 12', | ||
'}']) | ||
|
||
self.expect("frame variable v1_ref", | ||
substrs=['v1_ref = Active Type = int : {', | ||
'Value = 12', | ||
'}']) | ||
|
||
self.expect("frame variable v_v1", | ||
substrs=['v_v1 = Active Type = std::__1::variant<int, double, char> {', | ||
'Value = Active Type = int {', | ||
'Value = 12', | ||
'}', | ||
'}']) | ||
|
||
lldbutil.continue_to_breakpoint(self.process, bkpt) | ||
|
||
self.expect("frame variable v1", | ||
substrs=['v1 = Active Type = double {', | ||
'Value = 2', | ||
'}']) | ||
|
||
lldbutil.continue_to_breakpoint(self.process, bkpt) | ||
|
||
self.expect("frame variable v2", | ||
substrs=['v2 = Active Type = double {', | ||
'Value = 2', | ||
'}']) | ||
|
||
self.expect("frame variable v3", | ||
substrs=['v3 = Active Type = char {', | ||
'Value = \'A\'', | ||
'}']) | ||
|
||
self.expect("frame variable v_no_value", | ||
substrs=['v_no_value = No Value']) |
60 changes: 60 additions & 0 deletions
60
.../lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include <cstdio> | ||
#include <string> | ||
#include <vector> | ||
|
||
// If we have libc++ 4.0 or greater we should have <variant> | ||
// According to libc++ C++1z status page https://libcxx.llvm.org/cxx1z_status.html | ||
#if _LIBCPP_VERSION >= 4000 | ||
#include <variant> | ||
#define HAVE_VARIANT 1 | ||
#else | ||
#define HAVE_VARIANT 0 | ||
#endif | ||
|
||
struct S { | ||
operator int() { throw 42; } | ||
} ; | ||
|
||
|
||
int main() | ||
{ | ||
bool has_variant = HAVE_VARIANT ; | ||
|
||
printf( "%d\n", has_variant ) ; // break here | ||
|
||
#if HAVE_VARIANT == 1 | ||
std::variant<int, double, char> v1; | ||
std::variant<int, double, char> &v1_ref = v1; | ||
std::variant<int, double, char> v2; | ||
std::variant<int, double, char> v3; | ||
std::variant<std::variant<int,double,char>> v_v1 ; | ||
std::variant<int, double, char> v_no_value; | ||
|
||
v1 = 12; // v contains int | ||
v_v1 = v1 ; | ||
int i = std::get<int>(v1); | ||
printf( "%d\n", i ); // break here | ||
|
||
v2 = 2.0 ; | ||
double d = std::get<double>(v2) ; | ||
printf( "%f\n", d ); | ||
|
||
v3 = 'A' ; | ||
char c = std::get<char>(v3) ; | ||
printf( "%d\n", c ); | ||
|
||
// Checking v1 above and here to make sure we done maintain the incorrect | ||
// state when we change its value. | ||
v1 = 2.0; | ||
d = std::get<double>(v1) ; | ||
printf( "%f\n", d ); // break here | ||
|
||
try { | ||
v_no_value.emplace<0>(S()); | ||
} catch( ... ) {} | ||
|
||
printf( "%zu\n", v_no_value.index() ) ; | ||
#endif | ||
|
||
return 0; // break here | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.